spec/dynamoid/criteria/chain_spec.rb in dynamoid-0.4.1 vs spec/dynamoid/criteria/chain_spec.rb in dynamoid-0.5.0

- old
+ new

@@ -71,10 +71,18 @@ it 'finds records without an index' do @chain.query = {:password => 'Test123'} @chain.send(:records_without_index).should == [@user] end + it "doesn't crash if it finds a nil id in the index" do + @chain.query = {:name => 'Josh', "created_at.gt" => @time - 1.day} + Dynamoid::Adapter.expects(:query). + with("dynamoid_tests_index_user_created_ats_and_names", kind_of(Hash)). + returns([{ids: nil}, {ids: Set.new([42])}]) + @chain.send(:ids_from_index).should == Set.new([42]) + end + it 'defines each' do @chain.query = {:name => 'Josh'} @chain.each {|u| u.update_attribute(:name, 'Justin')} User.find(@user.id).name.should == 'Justin' @@ -86,47 +94,47 @@ @chain.collect {|u| u.name}.should == ['Josh'] end 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' } @chain.send(:range?).should be_false @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 end