Permalink
Browse files

num_pages bug when total_entries % per_page is not zero

  • Loading branch information...
niedhui committed Mar 28, 2012
1 parent f45dd87 commit 972e90b5d9740f7a969b79e2cf65e60dc3921a14
@@ -113,7 +113,7 @@ def limit_value
alias_method :per_page, :limit_value
def num_pages
- (self.total_entries && @opts[:per_page]) ? self.total_entries/@opts[:per_page] : nil
+ (self.total_entries && @opts[:per_page]) ? (total_entries.to_f / @opts[:per_page]).ceil : nil
end
alias_method :total_pages, :num_pages
@@ -70,4 +70,11 @@
near.limit_value.should == 25
end
end
+
+ context ":paginator :num_pages" do
+ it "when total=55 per=10 ,num_pages should be 6" do
+ 5.times { |i| Bar.create(:name => i.to_s, :location => [rand(358)-179,rand(358)-179]) }
+ Bar.geo_near([1,1]).per(10).num_pages.should == 6
+ end
+ end
end

0 comments on commit 972e90b

Please sign in to comment.