@@ -449,41 +449,42 @@ def test_index_language
449
449
def test_index_paged
450
450
# Create several pages worth of diary entries
451
451
create_list ( :diary_entry , 50 )
452
+ next_path = diary_entries_path
452
453
453
454
# Try and get the index
454
- get diary_entries_path
455
+ get next_path
455
456
assert_response :success
456
457
assert_select "article.diary_post" , :count => 20
457
- assert_select "li.page-item a.page-link" , :text => "Older Entries", :count => 1
458
- assert_select "li.page-item.disabled span.page-link" , :text => "Newer Entries", :count => 1
458
+ check_no_page_link "Newer Entries"
459
+ next_path = check_page_link "Older Entries"
459
460
460
461
# Try and get the second page
461
- get css_select ( "li.page-item .page-link" ) . last [ "href" ]
462
+ get next_path
462
463
assert_response :success
463
464
assert_select "article.diary_post" , :count => 20
464
- assert_select "li.page-item a.page-link" , :text => "Older Entries", :count => 1
465
- assert_select "li.page-item a.page-link" , :text => "Newer Entries", :count => 1
465
+ check_page_link "Newer Entries"
466
+ next_path = check_page_link "Older Entries"
466
467
467
468
# Try and get the third page
468
- get css_select ( "li.page-item .page-link" ) . last [ "href" ]
469
+ get next_path
469
470
assert_response :success
470
471
assert_select "article.diary_post" , :count => 10
471
- assert_select "li.page-item.disabled span.page-link" , :text => "Older Entries", :count => 1
472
- assert_select "li.page-item a.page-link" , :text => "Newer Entries", :count => 1
472
+ next_path = check_page_link "Newer Entries"
473
+ check_no_page_link "Older Entries"
473
474
474
475
# Go back to the second page
475
- get css_select ( "li.page-item .page-link" ) . first [ "href" ]
476
+ get next_path
476
477
assert_response :success
477
478
assert_select "article.diary_post" , :count => 20
478
- assert_select "li.page-item a.page-link" , :text => "Older Entries", :count => 1
479
- assert_select "li.page-item a.page-link" , :text => "Newer Entries", :count => 1
479
+ next_path = check_page_link "Newer Entries"
480
+ check_page_link "Older Entries"
480
481
481
482
# Go back to the first page
482
- get css_select ( "li.page-item .page-link" ) . first [ "href" ]
483
+ get next_path
483
484
assert_response :success
484
485
assert_select "article.diary_post" , :count => 20
485
- assert_select "li.page-item a.page-link" , :text => "Older Entries", :count => 1
486
- assert_select "li.page-item.disabled span.page-link" , :text => "Newer Entries", :count => 1
486
+ check_no_page_link "Newer Entries"
487
+ check_page_link "Older Entries"
487
488
end
488
489
489
490
def test_index_invalid_paged
@@ -962,4 +963,14 @@ def check_diary_index(*entries)
962
963
assert_select "a[href=?]" , "/user/#{ ERB ::Util . u ( entry . user . display_name ) } /diary/#{ entry . id } "
963
964
end
964
965
end
966
+
967
+ def check_no_page_link ( name )
968
+ assert_select "a.page-link" , { :text => /#{ Regexp . quote ( name ) } / , :count => 0 } , "unexpected #{ name } page link"
969
+ end
970
+
971
+ def check_page_link ( name )
972
+ assert_select "a.page-link" , { :text => /#{ Regexp . quote ( name ) } / } , "missing #{ name } page link" do |buttons |
973
+ return buttons . first . attributes [ "href" ] . value
974
+ end
975
+ end
965
976
end
0 commit comments