From 4b2ac7772a57afc6d705ac95a9efc12f100f211b Mon Sep 17 00:00:00 2001 From: Mark Serrano Date: Thu, 8 Oct 2015 17:15:06 -0400 Subject: [PATCH] - Fixes mislav/will_paginate#452 - Fix total_pages method to work with per_page = 0 --- lib/will_paginate/collection.rb | 2 +- spec/collection_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/will_paginate/collection.rb b/lib/will_paginate/collection.rb index 720c722ae..c4e11ce9b 100644 --- a/lib/will_paginate/collection.rb +++ b/lib/will_paginate/collection.rb @@ -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 diff --git a/spec/collection_spec.rb b/spec/collection_spec.rb index d561e8376..f855a9362 100644 --- a/spec/collection_spec.rb +++ b/spec/collection_spec.rb @@ -71,6 +71,13 @@ 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 create(2, 3, 2).should be_out_of_bounds