spec/dynamoid/adapter_spec.rb in dynamoid-0.1.2 vs spec/dynamoid/adapter_spec.rb in dynamoid-0.2.0
- old
+ new
@@ -29,20 +29,32 @@
Dynamoid::Adapter.write('dynamoid_tests_TestTable', {:id => '123'})
end
it 'reads through the adapter for one ID' do
- Dynamoid::Adapter.expects(:get_item).with('dynamoid_tests_TestTable', '123').returns(true)
+ Dynamoid::Adapter.expects(:get_item).with('dynamoid_tests_TestTable', '123', nil).returns(true)
Dynamoid::Adapter.read('dynamoid_tests_TestTable', '123')
end
it 'reads through the adapter for many IDs' do
Dynamoid::Adapter.expects(:batch_get_item).with({'dynamoid_tests_TestTable' => ['1', '2']}).returns(true)
Dynamoid::Adapter.read('dynamoid_tests_TestTable', ['1', '2'])
end
+
+ it 'reads through the adapter for one ID and a range key' do
+ Dynamoid::Adapter.expects(:get_item).with('dynamoid_tests_TestTable', '123', 2.0).returns(true)
+
+ Dynamoid::Adapter.read('dynamoid_tests_TestTable', '123', 2.0)
+ end
+
+ it 'reads through the adapter for many IDs and a range key' do
+ Dynamoid::Adapter.expects(:batch_get_item).with({'dynamoid_tests_TestTable' => [['1', 2.0], ['2', 2.0]]}).returns(true)
+
+ Dynamoid::Adapter.read('dynamoid_tests_TestTable', ['1', '2'], 2.0)
+ end
end
context 'with partitioning' do
before(:all) do
@previous_value = Dynamoid::Config.partitioning
@@ -70,12 +82,28 @@
it 'reads through the adapter for many IDs' do
Dynamoid::Adapter.expects(:batch_get_item).with('dynamoid_tests_TestTable' => (0...Dynamoid::Config.partition_size).collect{|n| "1.#{n}"} + (0...Dynamoid::Config.partition_size).collect{|n| "2.#{n}"}).returns({})
Dynamoid::Adapter.read('dynamoid_tests_TestTable', ['1', '2'])
end
+
+ it 'reads through the adapter for one ID and a range key' do
+ Dynamoid::Adapter.expects(:batch_get_item).with('dynamoid_tests_TestTable' => (0...Dynamoid::Config.partition_size).collect{|n| ["123.#{n}", 2.0]}).returns({})
+
+ Dynamoid::Adapter.read('dynamoid_tests_TestTable', '123', 2.0)
+ end
+ it 'reads through the adapter for many IDs and a range key' do
+ Dynamoid::Adapter.expects(:batch_get_item).with('dynamoid_tests_TestTable' => (0...Dynamoid::Config.partition_size).collect{|n| ["1.#{n}", 2.0]} + (0...Dynamoid::Config.partition_size).collect{|n| ["2.#{n}", 2.0]}).returns({})
+
+ Dynamoid::Adapter.read('dynamoid_tests_TestTable', ['1', '2'], 2.0)
+ end
+
it 'returns an ID with all partitions' do
Dynamoid::Adapter.id_with_partitions('1').should =~ (0...Dynamoid::Config.partition_size).collect{|n| "1.#{n}"}
+ end
+
+ it 'returns an ID and range key with all partitions' do
+ Dynamoid::Adapter.id_with_partitions([['1', 1.0]]).should =~ (0...Dynamoid::Config.partition_size).collect{|n| ["1.#{n}", 1.0]}
end
it 'returns a result for one partitioned element' do
@time = DateTime.now
@array =[{:id => '1.0', :updated_at => @time - 6.hours}, {:id => '1.1', :updated_at => @time - 3.hours}, {:id => '1.2', :updated_at => @time - 1.hour}, {:id => '1.3', :updated_at => @time - 6.hours}, {:id => '2.0', :updated_at => @time}]