Skip to content

Commit

Permalink
Use the new serialization pattern in bulk actions
Browse files Browse the repository at this point in the history
  • Loading branch information
liveh2o committed Mar 10, 2014
1 parent 0f40819 commit 1867e49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
20 changes: 8 additions & 12 deletions lib/active_remote/bulk.rb
Expand Up @@ -32,9 +32,8 @@ module ClassMethods
# Tag.create_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:name => 'foo') ])
#
def create_all(*records)
remote = self.new
remote.execute(:create_all, parse_records(records))
remote.serialize_records
response = rpc.execute(:create_all, parse_records(records))
serialize_records(response.records) if response.respond_to?(:records)
end

# Delete multiple records at the same time. Returns a collection of active
Expand All @@ -59,9 +58,8 @@ def create_all(*records)
# Tag.delete_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
#
def delete_all(*records)
remote = self.new
remote.execute(:delete_all, parse_records(records))
remote.serialize_records
response = rpc.execute(:delete_all, parse_records(records))
serialize_records(response.records) if response.respond_to?(:records)
end

# Destroy multiple records at the same time. Returns a collection of active
Expand All @@ -86,9 +84,8 @@ def delete_all(*records)
# Tag.destroy_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo') ])
#
def destroy_all(*records)
remote = self.new
remote.execute(:destroy_all, parse_records(records))
remote.serialize_records
response = rpc.execute(:destroy_all, parse_records(records))
serialize_records(response.records) if response.respond_to?(:records)
end

# Parse given records to get them ready to be built into a request.
Expand Down Expand Up @@ -135,9 +132,8 @@ def parse_records(*records)
# Tag.update_all(Generic::Remote::Tags.new(:records => [ Generic::Remote::Tag.new(:guid => 'foo', :name => 'baz') ])
#
def update_all(*records)
remote = self.new
remote.execute(:update_all, parse_records(records))
remote.serialize_records
response = rpc.execute(:update_all, parse_records(records))
serialize_records(response.records) if response.respond_to?(:records)
end
end
end
Expand Down
28 changes: 8 additions & 20 deletions spec/lib/active_remote/bulk_spec.rb
Expand Up @@ -5,37 +5,28 @@
let(:serialized_records) { double(:serialized_records) }

describe ".create_all" do
before {
Tag.stub(:parse_records).and_return(records)
Tag.any_instance.stub(:serialize_records).and_return(serialized_records)
}
before { Tag.better_stub(:parse_records).and_return(records) }

it "creates remote records" do
Tag.any_instance.should_receive(:execute).with(:create_all, records)
Tag.any_instance.better_receive(:execute).with(:create_all, records)
Tag.create_all(records)
end
end

describe ".delete_all" do
before {
Tag.stub(:parse_records).and_return(records)
Tag.any_instance.stub(:serialize_records).and_return(serialized_records)
}
before { Tag.better_stub(:parse_records).and_return(records) }

it "deletes remote records" do
Tag.any_instance.should_receive(:execute).with(:delete_all, records)
Tag.any_instance.better_receive(:execute).with(:delete_all, records)
Tag.delete_all(records)
end
end

describe ".destroy_all" do
before {
Tag.stub(:parse_records).and_return(records)
Tag.any_instance.stub(:serialize_records).and_return(serialized_records)
}
before { Tag.better_stub(:parse_records).and_return(records) }

it "destroys remote records" do
Tag.any_instance.should_receive(:execute).with(:destroy_all, records)
Tag.any_instance.better_receive(:execute).with(:destroy_all, records)
Tag.destroy_all(records)
end
end
Expand Down Expand Up @@ -78,13 +69,10 @@
end

describe ".update_all" do
before {
Tag.stub(:parse_records).and_return(records)
Tag.any_instance.stub(:serialize_records).and_return(serialized_records)
}
before { Tag.stub(:parse_records).and_return(records) }

it "updates remote records" do
Tag.any_instance.should_receive(:execute).with(:update_all, records)
Tag.any_instance.better_receive(:execute).with(:update_all, records)
Tag.update_all(records)
end
end
Expand Down

0 comments on commit 1867e49

Please sign in to comment.