Skip to content

Commit 74be3f8

Browse files
committed
Add older/newer links in front of diary, comment, issue, block pages
1 parent 29cc3d2 commit 74be3f8

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

app/views/diary_comments/_page.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<turbo-frame id="pagination" target="_top" data-turbo="false">
2+
<%= render "shared/pagination",
3+
:newer_id => @newer_comments_id,
4+
:older_id => @older_comments_id %>
5+
26
<table class="table table-striped" width="100%">
37
<thead>
48
<tr>

app/views/diary_entries/_page.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<turbo-frame id="pagination" target="_top" data-turbo="false">
22
<h4><%= t ".recent_entries" %></h4>
33

4+
<%= render "shared/pagination",
5+
:newer_id => @newer_entries_id,
6+
:older_id => @older_entries_id %>
7+
48
<%= render @entries %>
59

610
<%= render "shared/pagination",

app/views/issues/_page.html.erb

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<p><%= t ".issues_not_found" %></p>
77
<% end %>
88
<% else %>
9+
<%= render "shared/pagination",
10+
:newer_id => @newer_issues_id,
11+
:older_id => @older_issues_id %>
12+
913
<table class="table table-sm">
1014
<thead>
1115
<tr>
@@ -35,6 +39,7 @@
3539
<% end %>
3640
</tbody>
3741
</table>
42+
3843
<%= render "shared/pagination",
3944
:newer_id => @newer_issues_id,
4045
:older_id => @older_issues_id %>

app/views/user_blocks/_page.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<turbo-frame id="pagination" target="_top" data-turbo="false">
2+
<%= render "shared/pagination",
3+
:newer_id => @newer_user_blocks_id,
4+
:older_id => @older_user_blocks_id %>
5+
26
<table id="block_list" class="table table-borderless table-striped table-sm">
37
<thead>
48
<tr>

test/controllers/diary_entries_controller_test.rb

+26-15
Original file line numberDiff line numberDiff line change
@@ -449,41 +449,42 @@ def test_index_language
449449
def test_index_paged
450450
# Create several pages worth of diary entries
451451
create_list(:diary_entry, 50)
452+
next_path = diary_entries_path
452453

453454
# Try and get the index
454-
get diary_entries_path
455+
get next_path
455456
assert_response :success
456457
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"
459460

460461
# Try and get the second page
461-
get css_select("li.page-item .page-link").last["href"]
462+
get next_path
462463
assert_response :success
463464
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"
466467

467468
# Try and get the third page
468-
get css_select("li.page-item .page-link").last["href"]
469+
get next_path
469470
assert_response :success
470471
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"
473474

474475
# Go back to the second page
475-
get css_select("li.page-item .page-link").first["href"]
476+
get next_path
476477
assert_response :success
477478
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"
480481

481482
# Go back to the first page
482-
get css_select("li.page-item .page-link").first["href"]
483+
get next_path
483484
assert_response :success
484485
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"
487488
end
488489

489490
def test_index_invalid_paged
@@ -962,4 +963,14 @@ def check_diary_index(*entries)
962963
assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}"
963964
end
964965
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
965976
end

0 commit comments

Comments
 (0)