mongoid 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/mongoid/document.rb +3 -1
- data/mongoid.gemspec +1 -1
- data/spec/unit/mongoid/document_spec.rb +11 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/mongoid/document.rb
CHANGED
@@ -127,7 +127,9 @@ module Mongoid #:nodoc:
|
|
127
127
|
params[:page] || 1,
|
128
128
|
params[:per_page] || 20,
|
129
129
|
0) do |pager|
|
130
|
-
results = collection.find(selector, { :
|
130
|
+
results = collection.find(selector, { :sort => (params[:sort] || {}),
|
131
|
+
:limit => pager.per_page,
|
132
|
+
:offset => pager.offset })
|
131
133
|
pager.total_entries = results.count
|
132
134
|
pager.replace(results.collect { |doc| new(doc) })
|
133
135
|
end
|
data/mongoid.gemspec
CHANGED
@@ -419,7 +419,7 @@ describe Mongoid::Document do
|
|
419
419
|
context "when pagination parameters are passed" do
|
420
420
|
|
421
421
|
it "delegates to will paginate with the results" do
|
422
|
-
@collection.expects(:find).with({ :test => "Test" }, {:limit => 20, :offset => 20}).returns(@cursor)
|
422
|
+
@collection.expects(:find).with({ :test => "Test" }, { :sort => {}, :limit => 20, :offset => 20}).returns(@cursor)
|
423
423
|
Person.paginate(:conditions => { :test => "Test" }, :page => 2, :per_page => 20)
|
424
424
|
end
|
425
425
|
|
@@ -428,12 +428,21 @@ describe Mongoid::Document do
|
|
428
428
|
context "when pagination parameters are not passed" do
|
429
429
|
|
430
430
|
it "delegates to will paginate with default values" do
|
431
|
-
@collection.expects(:find).with({ :test => "Test" }, {:limit => 20, :offset => 0}).returns(@cursor)
|
431
|
+
@collection.expects(:find).with({ :test => "Test" }, { :sort => {}, :limit => 20, :offset => 0}).returns(@cursor)
|
432
432
|
Person.paginate(:conditions => { :test => "Test" })
|
433
433
|
end
|
434
434
|
|
435
435
|
end
|
436
436
|
|
437
|
+
context "when sorting paramters provided" do
|
438
|
+
|
439
|
+
it "adds the sorting parameters in the collection#find" do
|
440
|
+
@collection.expects(:find).with({ :test => "Test" }, { :sort => { :test => -1}, :limit => 20, :offset => 0}).returns(@cursor)
|
441
|
+
Person.paginate(:conditions => { :test => "Test" }, :sort => { :test => -1 })
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
445
|
+
|
437
446
|
end
|
438
447
|
|
439
448
|
describe "#parent" do
|