From 978a331738dbc94677f69f0921559a8e93b56c5a Mon Sep 17 00:00:00 2001 From: David Backeus Date: Tue, 25 Oct 2011 10:55:11 +0200 Subject: [PATCH] Support the page method with Mongoid. --- lib/will_paginate/mongoid.rb | 4 ++++ spec/finders/mongoid_spec.rb | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/will_paginate/mongoid.rb b/lib/will_paginate/mongoid.rb index 5624f34bb..a3b7588d7 100644 --- a/lib/will_paginate/mongoid.rb +++ b/lib/will_paginate/mongoid.rb @@ -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 diff --git a/spec/finders/mongoid_spec.rb b/spec/finders/mongoid_spec.rb index a01ba2a85..bf9082e81 100644 --- a/spec/finders/mongoid_spec.rb +++ b/spec/finders/mongoid_spec.rb @@ -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