Skip to content

Commit

Permalink
Mongo ruby driver removes all the values from the options hash, break…
Browse files Browse the repository at this point in the history
…ing any usage of them after the execution
  • Loading branch information
durran committed Nov 16, 2009
1 parent b6f4f65 commit 29883d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/mongoid/criteria.rb
Expand Up @@ -66,7 +66,7 @@ def all(selections = {})
def count(klass = nil)
return @count if @count
@klass = klass if klass
return @klass.collection.find(@selector, @options).count
return @klass.collection.find(@selector, @options.dup).count
end

# Adds a criterion to the +Criteria+ that specifies values that are not allowed
Expand Down Expand Up @@ -102,10 +102,10 @@ def excludes(exclusions = {})
def execute(klass = nil)
@klass = klass if klass
if type == :first
attributes = klass.collection.find_one(@selector, @options)
attributes = klass.collection.find_one(@selector, @options.dup)
return attributes ? @klass.instantiate(attributes) : nil
else
attributes = @klass.collection.find(@selector, @options)
attributes = @klass.collection.find(@selector, @options.dup)
if attributes
@count = attributes.count
return attributes.collect { |doc| @klass.instantiate(doc) }
Expand All @@ -128,7 +128,9 @@ def execute(klass = nil)
#
# Returns: <tt>self</tt>
def extras(extras)
@options = extras; filter_options; self
@options = extras
filter_options
self
end

GROUP_REDUCE = "function(obj, prev) { prev.group.push(obj); }"
Expand Down
8 changes: 5 additions & 3 deletions spec/unit/mongoid/criteria_spec.rb
Expand Up @@ -193,8 +193,9 @@
context "when page is provided" do

it "sets the limit and skip options" do
@criteria.extras({ :page => 5 })
@criteria.options.should == { :skip => 80, :limit => 20 }
@criteria.extras({ :page => "2" })
@criteria.page.should == 2
@criteria.options.should == { :skip => 20, :limit => 20 }
end

end
Expand All @@ -211,8 +212,9 @@
context "when page and per_page both provided" do

it "sets the limit and skip options" do
@criteria.extras({ :per_page => 30, :page => 4 })
@criteria.extras({ :per_page => 30, :page => "4" })
@criteria.options.should == { :skip => 90, :limit => 30 }
@criteria.page.should == 4
end

end
Expand Down

0 comments on commit 29883d1

Please sign in to comment.