Skip to content
Browse files

fix counting in pagination when Integer has length method (Ruby Facets)

  • Loading branch information...
1 parent 698d803 commit d2fb846f0424939a7ba72534e74fe6d8209a5867 @jingoro jingoro committed with Oct 22, 2009
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/will_paginate/finder.rb
  2. +16 −0 test/finder_test.rb
View
2 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:
View
16 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

0 comments on commit d2fb846

Please sign in to comment.
Something went wrong with that request. Please try again.