Skip to content

Commit

Permalink
- Fixes mislav#452
Browse files Browse the repository at this point in the history
- Fix total_pages method to work with per_page = 0
  • Loading branch information
Mark Serrano committed Oct 8, 2015
1 parent 74a6cd0 commit 41afdfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/will_paginate/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module WillPaginate
# This module provides few of these methods.
module CollectionMethods
def total_pages
total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil
total_entries.zero? || per_page.zero? ? 1 : (total_entries / per_page.to_f).ceil
end

# current_page - 1 or nil if there is no previous page
Expand Down
13 changes: 10 additions & 3 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
result = (1..50).to_a.paginate
result.current_page.should == 1
result.size.should == 30
end
end

it "should give total_entries precedence over actual size" do
%w(a b c).paginate(:total_entries => 5).total_entries.should == 5
Expand Down Expand Up @@ -68,8 +68,15 @@
collection = create(3, 1, 3)
collection.previous_page.should == 2
collection.next_page.should be_nil
end
end
end
end

describe "num_page is zero" do
it "should have total_pages 1 when num_page is zero" do
collection = create(1,0,1)
collection.total_pages.should == 1
end
end

describe "out of bounds" do
it "is out of bounds when page number is too high" do
Expand Down

0 comments on commit 41afdfe

Please sign in to comment.