Skip to content

Commit

Permalink
Query#object_ids was not passing keys argument through to criteria. M…
Browse files Browse the repository at this point in the history
…ade it so Query#object_ids with no arguments returns the criteria's object_ids.
  • Loading branch information
jnunemaker committed May 17, 2010
1 parent 711f440 commit 407583c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/plucky/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def initialize(collection, opts={})
end

def object_ids(*keys)
criteria.object_ids = @object_ids
return criteria.object_ids if keys.empty?
criteria.object_ids = *keys
self
end

Expand Down
17 changes: 16 additions & 1 deletion test/plucky/test_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QueryTest < Test::Unit::TestCase
subject[:skip] = 1
subject[:skip].should == 1
end

should "set key on criteria for criteria" do
subject[:foo] = 'bar'
subject[:foo].should == 'bar'
Expand Down Expand Up @@ -274,6 +274,21 @@ class QueryTest < Test::Unit::TestCase
end
end

context "#object_ids" do
setup { @query = Query.new(@collection) }
subject { @query }

should "set criteria's object_ids" do
subject.criteria.expects(:object_ids=).with([:foo, :bar])
subject.object_ids(:foo, :bar)
end

should "return current object ids if keys argument is empty" do
subject.object_ids(:foo, :bar)
subject.object_ids.should == [:foo, :bar]
end
end

context "#merge" do
should "overwrite options" do
query1 = Query.new(@collection, :skip => 5, :limit => 5)
Expand Down

0 comments on commit 407583c

Please sign in to comment.