Permalink
Browse files

Allowing page and per_page param to be passed as string to paginate

  • Loading branch information...
1 parent 5a5aa9b commit fae618353dd0d1f35c50a8a05e1c529ea604d815 @vicentemundim committed Jul 21, 2011
Showing with 6 additions and 2 deletions.
  1. +2 −2 lib/mongoid/paginate.rb
  2. +4 −0 spec/mongoid/paginate_spec.rb
View
@@ -1,8 +1,8 @@
module Mongoid
module Paginate
def paginate(options={})
- per_page = options[:per_page] || 20
- page = options[:page] || 1
+ per_page = (options[:per_page] || 20).to_i
+ page = (options[:page] || 1).to_i
offset = (page - 1) * per_page
WillPaginate::Collection.create(page, per_page, count) do |pager|
@@ -31,6 +31,10 @@ class Document
Document.paginate(:per_page => 5, :page => 3).should == documents[10..14]
end
+ it "should return an array with the specified documents per page as string of the specified page as string" do
+ Document.paginate(:per_page => '5', :page => '3').should == documents[10..14]
+ end
+
it "should return an array with the total entries" do
Document.paginate(:per_page => 5, :page => 3).total_entries.should == total_entries
end

0 comments on commit fae6183

Please sign in to comment.