Skip to content

Commit

Permalink
Change output of "page_entries_info" on single-page collection and er…
Browse files Browse the repository at this point in the history
…raneous output with empty collection as reported by Tim Chater.
  • Loading branch information
mislav committed Apr 21, 2008
1 parent 5b0e0b8 commit cc1516d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/will_paginate/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,19 @@ def paginated_section(*args, &block)
# <%= page_entries_info @posts %>
# #-> Displaying entries 6 - 10 of 26 in total
def page_entries_info(collection)
%{Displaying entries <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
collection.offset + 1,
collection.offset + collection.length,
collection.total_entries
]
if collection.total_pages < 2
case collection.size
when 0; 'No entries found'
when 1; 'Displaying <b>1</b> entry'
else; "Displaying <b>all #{collection.size}</b> entries"
end
else
%{Displaying entries <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
collection.offset + 1,
collection.offset + collection.length,
collection.total_entries
]
end
end

def self.total_pages_for_collection(collection) #:nodoc:
Expand Down
13 changes: 13 additions & 0 deletions test/view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ def test_page_entries_info
assert_equal %{Displaying entries <b>25&nbsp;-&nbsp;26</b> of <b>26</b> in total},
@html_result
end

def test_page_entries_info_with_single_page_collection
@template = '<%= page_entries_info collection %>'

paginate(('a'..'d').to_a.paginate(:page => 1, :per_page => 5))
assert_equal %{Displaying <b>all 4</b> entries}, @html_result

paginate(['a'].paginate(:page => 1, :per_page => 5))
assert_equal %{Displaying <b>1</b> entry}, @html_result

paginate([].paginate(:page => 1, :per_page => 5))
assert_equal %{No entries found}, @html_result
end

## parameter handling in page links ##

Expand Down

0 comments on commit cc1516d

Please sign in to comment.