Skip to content

Commit

Permalink
Fixed a bug in AWS::DynamoDB#batch_get
Browse files Browse the repository at this point in the history
Added missing tests and corrected a bug.
Fixes #161
  • Loading branch information
trevorrowe committed Feb 18, 2013
1 parent 28c97af commit 5dc430a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/aws/dynamo_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def tables
def batch_get &block
batch = BatchGet.new(:config => config)
yield(batch)
batch.enumerator
batch.to_enum(:each)
end

# Yields a batch for writing (put and delete) items across multiple
Expand Down
28 changes: 24 additions & 4 deletions spec/aws/dynamo_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,43 @@ module AWS

end

context '#batch_get' do

it 'yeilds a batch get object' do
yielded = nil
dynamo_db.batch_get do |batch|
yielded = batch
end
yielded.should be_a(DynamoDB::BatchGet)
end

it 'returns the batch enumerator' do
enumerator = double('enumerator')
batch = double('batch')
batch.should_receive(:to_enum).and_return(enumerator)
DynamoDB::BatchGet.should_receive(:new).and_return(batch)
dynamo_db.batch_get {|batch|}.should be(enumerator)
end

end

context '#batch_write' do

let(:resp) {
let(:resp) {
r = client.stub_for(:batch_write_item)
r.data['UnprocessedItems'] = {}
r
}

it 'calls #batch_write_item on the client' do

client.should_receive(:batch_write_item).with(:request_items=>{
"table1"=>[
{:put_request=>{:item=>{"id"=>{:n=>"1"}}}},
{:put_request=>{:item=>{"id"=>{:n=>"2"}}}},
{:delete_request=>{:key=>{:hash_key_element=>{:n=>"3"}}}},
{:delete_request=>{:key=>{:hash_key_element=>{:n=>"3"}}}},
{:delete_request=>{:key=>{:hash_key_element=>{:n=>"4"}}}}
],
],
"table2"=>[
{:put_request=>{:item=>{"id"=>{:s=>"1"}}}},
{:put_request=>{:item=>{"id"=>{:s=>"2"}}}},
Expand Down

0 comments on commit 5dc430a

Please sign in to comment.