Skip to content

Commit

Permalink
Support the page method with Mongoid.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbackeus committed Jun 14, 2012
1 parent c87a255 commit a84f7ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/will_paginate/mongoid.rb
Expand Up @@ -11,6 +11,10 @@ def paginate(options = {})
@page_multiplier = current_page - 1
limit(per_page).skip(@page_multiplier * per_page)
end

def page(page)
paginate(:page => page)
end
end

module CollectionMethods
Expand Down
19 changes: 11 additions & 8 deletions spec/finders/mongoid_spec.rb
Expand Up @@ -8,18 +8,21 @@ class MongoidModel
end

describe "will paginate mongoid" do
let(:criteria) { MongoidModel.criteria }

it "should have the #paginate method" do
criteria.should respond_to(:paginate)
before(:all) do
MongoidModel.delete_all
4.times { MongoidModel.create! }
end

describe "pagination" do
before(:all) do
MongoidModel.delete_all
4.times { MongoidModel.create! }
let(:criteria) { MongoidModel.criteria }

describe "#page" do
it "should forward to the paginate method" do
criteria.expects(:paginate).with(:page => 2).returns("itself")
criteria.page(2).should == "itself"
end
end

describe "#paginate" do
it "should use criteria" do
criteria.paginate.should be_instance_of(::Mongoid::Criteria)
end
Expand Down

0 comments on commit a84f7ea

Please sign in to comment.