From 2b43d0e48892c7c380633b4df5bc15ef3c018f24 Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Fri, 11 May 2012 11:40:53 +0530 Subject: [PATCH] use hash_key instead of using 'id'. see #43 --- lib/dynamoid/criteria/chain.rb | 2 +- spec/dynamoid/criteria/chain_spec.rb | 18 +++++++++--------- spec/dynamoid/criteria_spec.rb | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/dynamoid/criteria/chain.rb b/lib/dynamoid/criteria/chain.rb index 4dda34f..65d7b2c 100644 --- a/lib/dynamoid/criteria/chain.rb +++ b/lib/dynamoid/criteria/chain.rb @@ -201,7 +201,7 @@ def query_keys def range? return false unless source.range_key - query_keys == ['id'] || (query_keys.to_set == ['id', source.range_key.to_s].to_set) + query_keys == [source.hash_key.to_s] || (query_keys.to_set == [source.hash_key.to_s, source.range_key.to_s].to_set) end def start_key diff --git a/spec/dynamoid/criteria/chain_spec.rb b/spec/dynamoid/criteria/chain_spec.rb index dad9356..df97d4f 100644 --- a/spec/dynamoid/criteria/chain_spec.rb +++ b/spec/dynamoid/criteria/chain_spec.rb @@ -88,10 +88,10 @@ it 'finds range querys' do @chain = Dynamoid::Criteria::Chain.new(Tweet) - @chain.query = { :id => 'test' } + @chain.query = { :tweet_id => 'test' } @chain.send(:range?).should be_true - @chain.query = {:id => 'test', :group => 'xx'} + @chain.query = {:tweet_id => 'test', :group => 'xx'} @chain.send(:range?).should be_true @chain.query = { :group => 'xx' } @@ -100,32 +100,32 @@ @chain.query = { :group => 'xx', :msg => 'hai' } @chain.send(:range?).should be_false end - + context 'range queries' do before do @tweet1 = Tweet.create(:tweet_id => "x", :group => "one") @tweet2 = Tweet.create(:tweet_id => "x", :group => "two") - @tweet3 = Tweet.create(:tweet_id => "xx", :group => "two") + @tweet3 = Tweet.create(:tweet_id => "xx", :group => "two") @chain = Dynamoid::Criteria::Chain.new(Tweet) end - + it 'finds tweets with a simple range query' do @chain.query = { :tweet_id => "x" } @chain.send(:records_with_range).size.should == 2 @chain.all.size.should == 2 - @chain.limit(1).size.should == 1 + @chain.limit(1).size.should == 1 end - + it 'finds tweets with a start' do @chain.query = { :tweet_id => "x" } @chain.start(@tweet1) @chain.all.should =~ [@tweet2] end - + it 'finds one specific tweet' do @chain = Dynamoid::Criteria::Chain.new(Tweet) @chain.query = { :tweet_id => "xx", :group => "two" } - @chain.send(:records_with_range).should == [@tweet3] + @chain.send(:records_with_range).should == [@tweet3] end end diff --git a/spec/dynamoid/criteria_spec.rb b/spec/dynamoid/criteria_spec.rb index 1d8a473..15a03fc 100644 --- a/spec/dynamoid/criteria_spec.rb +++ b/spec/dynamoid/criteria_spec.rb @@ -57,10 +57,10 @@ User.where(:name => 'x').consistent.first Dynamoid::Adapter.expects(:query).with { |table_name, options| options[:consistent_read] == true }.returns([]) - Tweet.where(:id => 'xx', :group => 'two').consistent.all + Tweet.where(:tweet_id => 'xx', :group => 'two').consistent.all Dynamoid::Adapter.expects(:query).with { |table_name, options| options[:consistent_read] == false }.returns([]) - Tweet.where(:id => 'xx', :group => 'two').all + Tweet.where(:tweet_id => 'xx', :group => 'two').all end end