diff --git a/lib/will_paginate/finder.rb b/lib/will_paginate/finder.rb index 1bbc77076..a7f130b49 100644 --- a/lib/will_paginate/finder.rb +++ b/lib/will_paginate/finder.rb @@ -235,7 +235,7 @@ def wp_count(options, args, finder) counter.call end - count.respond_to?(:length) ? count.length : count + (!count.is_a?(Integer) && count.respond_to?(:length)) ? count.length : count end def wp_parse_options(options) #:nodoc: diff --git a/test/finder_test.rb b/test/finder_test.rb index a16c84698..a47707b0c 100644 --- a/test/finder_test.rb +++ b/test/finder_test.rb @@ -39,6 +39,22 @@ def test_parameter_api assert_nothing_raised { Topic.paginate :page => 1, :count => nil } end + def test_counting_when_integer_has_length_method + Integer.module_eval { def length; to_s.length; end } + begin + assert_equal 2, 11.length + entries = Developer.paginate :page => 1, :per_page => 5 + assert_equal 11, entries.total_entries + assert_equal 5, entries.size + assert_equal 3, entries.total_pages + ensure + begin + Integer.module_eval { remove_method :length } + rescue + end + end + end + def test_paginate_with_per_page entries = Topic.paginate :page => 1, :per_page => 1 assert_equal 1, entries.size