Skip to content

Commit

Permalink
num_pages bug when total_entries % per_page is not zero
Browse files Browse the repository at this point in the history
  • Loading branch information
niedhui committed Mar 28, 2012
1 parent f45dd87 commit 972e90b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid_spacial/spacial/geo_near_results.rb
Expand Up @@ -113,7 +113,7 @@ def limit_value
alias_method :per_page, :limit_value alias_method :per_page, :limit_value


def num_pages 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 end
alias_method :total_pages, :num_pages alias_method :total_pages, :num_pages


Expand Down
7 changes: 7 additions & 0 deletions spec/functional/mongoid/spacial/geo_near_results_spec.rb
Expand Up @@ -70,4 +70,11 @@
near.limit_value.should == 25 near.limit_value.should == 25
end end
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 end

0 comments on commit 972e90b

Please sign in to comment.