Methods
public instance
- test_adding_additional_parameters
- test_adding_additional_route_parameters
- test_adding_anchor_parameter
- test_collection_name_can_be_guessed
- test_complex_custom_page_param
- test_container_id
- test_custom_routing_page_param
- test_custom_routing_page_param_with_dot_separator
- test_custom_routing_with_first_page_hidden
- test_deprecation_notices_with_page_count
- test_escaping_of_urls
- test_full_output
- test_inferred_collection_name_raises_error_when_nil
- test_no_pagination_when_page_count_is_one
- test_page_entries_info
- test_page_entries_info_with_custom_entry_name
- test_page_entries_info_with_longer_class_name
- test_page_entries_info_with_single_page_collection
- test_paginated_section
- test_prev_label_deprecated
- test_prev_next_links_have_classnames
- test_removing_arbitrary_parameters
- test_rescue_response_hook_presence
- test_will_paginate
- test_will_paginate_doesnt_preserve_parameters_on_post
- test_will_paginate_eliminates_small_gaps
- test_will_paginate_preserves_parameters_on_get
- test_will_paginate_using_renderer_class
- test_will_paginate_using_renderer_instance
- test_will_paginate_windows
- test_will_paginate_with_atmark_url
- test_will_paginate_with_custom_page_param
- test_will_paginate_with_options
- test_will_paginate_without_container
- test_will_paginate_without_page_links
Public instance methods
test_adding_additional_parameters
()
[show source]
# File test/view_test.rb, line 254 def test_adding_additional_parameters paginate({}, :params => { :foo => 'bar' }) assert_links_match /foo=bar/ end
test_adding_additional_route_parameters
()
[show source]
# File test/view_test.rb, line 270 def test_adding_additional_route_parameters paginate({}, :params => { :controller => 'baz', :action => 'list' }) assert_links_match %r{\Wbaz/list\W} end
test_adding_anchor_parameter
()
[show source]
# File test/view_test.rb, line 259 def test_adding_anchor_parameter paginate({}, :params => { :anchor => 'anchor' }) assert_links_match /#anchor$/ end
test_collection_name_can_be_guessed
()
[show source]
# File test/view_test.rb, line 345 def test_collection_name_can_be_guessed collection = mock collection.expects(:total_pages).returns(1) @template = '<%= will_paginate options %>' @controller.controller_name = 'developers' @view.assigns['developers'] = collection paginate(nil) end
test_complex_custom_page_param
()
[show source]
# File test/view_test.rb, line 291 def test_complex_custom_page_param @request.params :developers => { :page => 2 } paginate({ :page => 2 }, :param_name => 'developers[page]') do assert_select 'a[href]', 4 do |links| assert_links_match /\?developers%5Bpage%5D=\d+$/, links validate_page_numbers [1,1,3,3], links, 'developers[page]' end end end
test_container_id
()
[show source]
# File test/view_test.rb, line 153 def test_container_id paginate do |div| assert_nil div.first['id'] end # magic ID paginate({}, :id => true) do |div| assert_equal 'fixnums_pagination', div.first['id'] end # explicit ID paginate({}, :id => 'custom_id') do |div| assert_equal 'custom_id', div.first['id'] end end
test_custom_routing_page_param
()
[show source]
# File test/view_test.rb, line 302 def test_custom_routing_page_param @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil paginate :per_page => 2 do assert_select 'a[href]', 6 do |links| assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2] end end end
test_custom_routing_page_param_with_dot_separator
()
[show source]
# File test/view_test.rb, line 311 def test_custom_routing_page_param_with_dot_separator @request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots' paginate :per_page => 2 do assert_select 'a[href]', 6 do |links| assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2] end end end
test_custom_routing_with_first_page_hidden
()
[show source]
# File test/view_test.rb, line 320 def test_custom_routing_with_first_page_hidden @request.symbolized_path_parameters.update :controller => 'ibocorp', :action => nil paginate :page => 2, :per_page => 2 do assert_select 'a[href]', 7 do |links| assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3] end end end
test_deprecation_notices_with_page_count
()
[show source]
# File test/view_test.rb, line 336 def test_deprecation_notices_with_page_count collection = LegacyCollection.new(1, 1, 2) assert_deprecated collection.class.name do paginate collection end end
test_escaping_of_urls
()
[show source]
# File test/view_test.rb, line 107 def test_escaping_of_urls paginate({:page => 1, :per_page => 1, :total_entries => 2}, :page_links => false, :params => { :tag => '<br>' }) assert_select 'a[href]', 1 do |links| query = links.first['href'].split('?', 2)[1] assert_equal %w(page=2 tag=%3Cbr%3E), query.split('&').sort end end
test_full_output
()
[show source]
# File test/view_test.rb, line 92 def test_full_output paginate expected = "<div class=\"pagination\"><span class=\"disabled prev_page\">« Previous</span>\n<span class=\"current\">1</span>\n<a href=\"/foo/bar?page=2\" rel=\"next\">2</a>\n<a href=\"/foo/bar?page=3\">3</a>\n<a href=\"/foo/bar?page=2\" class=\"next_page\" rel=\"next\">Next »</a></div>\n" expected.strip!.gsub!(/\s{2,}/, ' ') assert_dom_equal expected, @html_result end
test_inferred_collection_name_raises_error_when_nil
()
[show source]
# File test/view_test.rb, line 357 def test_inferred_collection_name_raises_error_when_nil @template = '<%= will_paginate options %>' @controller.controller_name = 'developers' e = assert_raise ArgumentError do paginate(nil) end assert e.message.include?('@developers') end
test_no_pagination_when_page_count_is_one
()
[show source]
# File test/view_test.rb, line 32 def test_no_pagination_when_page_count_is_one paginate :per_page => 30 assert_equal '', @html_result end
test_page_entries_info
()
[show source]
# File test/view_test.rb, line 184 def test_page_entries_info @template = '<%= page_entries_info collection %>' array = ('a'..'z').to_a paginate array.paginate(:page => 2, :per_page => 5) assert_equal %{Displaying strings <b>6 - 10</b> of <b>26</b> in total}, @html_result paginate array.paginate(:page => 7, :per_page => 4) assert_equal %{Displaying strings <b>25 - 26</b> of <b>26</b> in total}, @html_result end
test_page_entries_info_with_custom_entry_name
()
[show source]
# File test/view_test.rb, line 221 def test_page_entries_info_with_custom_entry_name @template = '<%= page_entries_info collection, :entry_name => "author" %>' entries = (1..20).to_a paginate(entries.paginate(:page => 1, :per_page => 5)) assert_equal %{Displaying authors <b>1 - 5</b> of <b>20</b> in total}, @html_result paginate(entries.paginate(:page => 1, :per_page => 20)) assert_equal %{Displaying <b>all 20</b> authors}, @html_result paginate(['a'].paginate(:page => 1, :per_page => 5)) assert_equal %{Displaying <b>1</b> author}, @html_result paginate([].paginate(:page => 1, :per_page => 5)) assert_equal %{No authors found}, @html_result end
test_page_entries_info_with_longer_class_name
()
[show source]
# File test/view_test.rb, line 198 def test_page_entries_info_with_longer_class_name @template = '<%= page_entries_info collection %>' collection = ('a'..'z').to_a.paginate collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType')) paginate collection assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'" end
test_page_entries_info_with_single_page_collection
()
[show source]
# File test/view_test.rb, line 208 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> strings}, @html_result paginate(['a'].paginate(:page => 1, :per_page => 5)) assert_equal %{Displaying <b>1</b> string}, @html_result paginate([].paginate(:page => 1, :per_page => 5)) assert_equal %{No entries found}, @html_result end
test_paginated_section
()
other helpers ##
[show source]
# File test/view_test.rb, line 171 def test_paginated_section @template = "<% paginated_section collection, options do %>\n<%= content_tag :div, '', :id => \"developers\" %>\n<% end %>\n" paginate assert_select 'div.pagination', 2 assert_select 'div.pagination + div#developers', 1 end
test_prev_label_deprecated
()
[show source]
# File test/view_test.rb, line 84 def test_prev_label_deprecated assert_deprecated ':previous_label' do paginate({ :page => 2 }, :prev_label => 'Deprecated') do assert_select 'a[href]:first-child', 'Deprecated' end end end
test_prev_next_links_have_classnames
()
[show source]
# File test/view_test.rb, line 77 def test_prev_next_links_have_classnames paginate do |pagination| assert_select 'span.disabled.prev_page:first-child' assert_select 'a.next_page[href]:last-child' end end
test_removing_arbitrary_parameters
()
[show source]
# File test/view_test.rb, line 264 def test_removing_arbitrary_parameters @request.params :foo => 'bar' paginate({}, :params => { :foo => nil }) assert_no_links_match /foo=bar/ end
test_rescue_response_hook_presence
()
only on Rails 2
[show source]
# File test/view_test.rb, line 369 def test_rescue_response_hook_presence assert_equal :not_found, ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] end
test_will_paginate
()
basic pagination ##
[show source]
# File test/view_test.rb, line 19 def test_will_paginate paginate do |pagination| assert_select 'a[href]', 3 do |elements| validate_page_numbers [2,3,2], elements assert_select elements.last, ':last-child', "Next »" end assert_select 'span', 2 assert_select 'span.disabled:first-child', '« Previous' assert_select 'span.current', '1' assert_equal '« Previous 1 2 3 Next »', pagination.first.inner_text end end
test_will_paginate_doesnt_preserve_parameters_on_post
()
[show source]
# File test/view_test.rb, line 247 def test_will_paginate_doesnt_preserve_parameters_on_post @request.post @request.params :foo => 'bar' paginate assert_no_links_match /foo=bar/ end
test_will_paginate_eliminates_small_gaps
()
[show source]
# File test/view_test.rb, line 145 def test_will_paginate_eliminates_small_gaps paginate({ :page => 6, :per_page => 1 }, :inner_window => 2) do assert_select 'a[href]', 12 do |elements| validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements end end end
test_will_paginate_preserves_parameters_on_get
()
parameter handling in page links ##
[show source]
# File test/view_test.rb, line 241 def test_will_paginate_preserves_parameters_on_get @request.params :foo => { :bar => 'baz' } paginate assert_links_match /foo%5Bbar%5D=baz/ end
test_will_paginate_using_renderer_class
()
[show source]
# File test/view_test.rb, line 57 def test_will_paginate_using_renderer_class paginate({}, :renderer => AdditionalLinkAttributesRenderer) do assert_select 'a[default=true]', 3 end end
test_will_paginate_using_renderer_instance
()
[show source]
# File test/view_test.rb, line 63 def test_will_paginate_using_renderer_instance renderer = WillPaginate::LinkRenderer.new renderer.gap_marker = '<span class="my-gap">~~</span>' paginate({ :per_page => 2 }, :inner_window => 0, :outer_window => 0, :renderer => renderer) do assert_select 'span.my-gap', '~~' end renderer = AdditionalLinkAttributesRenderer.new(:title => 'rendered') paginate({}, :renderer => renderer) do assert_select 'a[title=rendered]', 3 end end
test_will_paginate_windows
()
[show source]
# File test/view_test.rb, line 133 def test_will_paginate_windows paginate({ :page => 6, :per_page => 1 }, :inner_window => 1) do |pagination| assert_select 'a[href]', 8 do |elements| validate_page_numbers [5,1,2,5,7,10,11,7], elements assert_select elements.first, 'a', '« Previous' assert_select elements.last, 'a', 'Next »' end assert_select 'span.current', '6' assert_equal '« Previous 1 2 … 5 6 7 … 10 11 Next »', pagination.first.inner_text end end
test_will_paginate_with_atmark_url
()
[show source]
# File test/view_test.rb, line 283 def test_will_paginate_with_atmark_url @request.symbolized_path_parameters[:action] = "@tag" renderer = WillPaginate::LinkRenderer.new paginate({ :page => 1 }, :renderer=>renderer) assert_links_match %r[/foo/@tag\?page=\d] end
test_will_paginate_with_custom_page_param
()
[show source]
# File test/view_test.rb, line 275 def test_will_paginate_with_custom_page_param paginate({ :page => 2 }, :param_name => :developers_page) do assert_select 'a[href]', 4 do |elements| validate_page_numbers [1,1,3,3], elements, :developers_page end end end
test_will_paginate_with_options
()
[show source]
# File test/view_test.rb, line 37 def test_will_paginate_with_options paginate({ :page => 2 }, :class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do assert_select 'a[href]', 4 do |elements| validate_page_numbers [1,1,3,3], elements # test rel attribute values: assert_select elements[1], 'a', '1' do |link| assert_equal 'prev start', link.first['rel'] end assert_select elements.first, 'a', "Prev" do |link| assert_equal 'prev start', link.first['rel'] end assert_select elements.last, 'a', "Next" do |link| assert_equal 'next', link.first['rel'] end end assert_select 'span.current', '2' end end
test_will_paginate_without_container
()
advanced options for pagination ##
[show source]
# File test/view_test.rb, line 119 def test_will_paginate_without_container paginate({}, :container => false) assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t' assert_select 'a[href]', 3 end
test_will_paginate_without_page_links
()
[show source]
# File test/view_test.rb, line 125 def test_will_paginate_without_page_links paginate({ :page => 2 }, :page_links => false) do assert_select 'a[href]', 2 do |elements| validate_page_numbers [1,3], elements end end end