diff --git a/lib/mongoid/criteria.rb b/lib/mongoid/criteria.rb index 63f46573a5..5b9c05d057 100644 --- a/lib/mongoid/criteria.rb +++ b/lib/mongoid/criteria.rb @@ -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 @@ -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) } @@ -128,7 +128,9 @@ def execute(klass = nil) # # Returns: self def extras(extras) - @options = extras; filter_options; self + @options = extras + filter_options + self end GROUP_REDUCE = "function(obj, prev) { prev.group.push(obj); }" diff --git a/spec/unit/mongoid/criteria_spec.rb b/spec/unit/mongoid/criteria_spec.rb index 6a8bae37d1..849d712d69 100644 --- a/spec/unit/mongoid/criteria_spec.rb +++ b/spec/unit/mongoid/criteria_spec.rb @@ -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 @@ -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