Skip to content

Commit

Permalink
fix counting in pagination when Integer has length method (Ruby Facets)
Browse files Browse the repository at this point in the history
  • Loading branch information
jingoro authored and mislav committed Sep 9, 2010
1 parent 698d803 commit d2fb846
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/will_paginate/finder.rb
Expand Up @@ -235,7 +235,7 @@ def wp_count(options, args, finder)
counter.call counter.call
end end


count.respond_to?(:length) ? count.length : count (!count.is_a?(Integer) && count.respond_to?(:length)) ? count.length : count
end end


def wp_parse_options(options) #:nodoc: def wp_parse_options(options) #:nodoc:
Expand Down
16 changes: 16 additions & 0 deletions test/finder_test.rb
Expand Up @@ -39,6 +39,22 @@ def test_parameter_api
assert_nothing_raised { Topic.paginate :page => 1, :count => nil } assert_nothing_raised { Topic.paginate :page => 1, :count => nil }
end 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 def test_paginate_with_per_page
entries = Topic.paginate :page => 1, :per_page => 1 entries = Topic.paginate :page => 1, :per_page => 1
assert_equal 1, entries.size assert_equal 1, entries.size
Expand Down

0 comments on commit d2fb846

Please sign in to comment.