From 7377ea67e81c2bb34a82106e370a4bc9ab77d23a Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 9 Aug 2025 03:39:38 +0300 Subject: [PATCH] Fix next page boundary condition for user notes --- app/controllers/notes_controller.rb | 10 ++++- app/views/notes/_notes_paging_nav.html.erb | 10 ++--- test/system/user_notes_test.rb | 45 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 test/system/user_notes_test.rb diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 903d3ffe0..38d0edc0b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -13,6 +13,8 @@ class NotesController < ApplicationController before_action :lookup_user, :only => [:index] around_action :web_timeout + PAGE_SIZE = 10 + ## # Display a list of notes by a specified user def index @@ -21,11 +23,15 @@ class NotesController < ApplicationController @params = params.permit(:display_name, :status) @title = t ".title", :user => @user.display_name @page = (params[:page] || 1).to_i - @page_size = 10 @notes = @user.notes @notes = @notes.visible unless current_user&.moderator? @notes = @notes.where(:status => params[:status]) unless params[:status] == "all" || params[:status].blank? - @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author) + @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * PAGE_SIZE).limit(PAGE_SIZE + 1).preload(:comments => :author) + @notes = @notes.to_a + if @notes.size > PAGE_SIZE + @notes.pop + @next_page = true + end render :layout => "site" end diff --git a/app/views/notes/_notes_paging_nav.html.erb b/app/views/notes/_notes_paging_nav.html.erb index 5209256d6..54378b750 100644 --- a/app/views/notes/_notes_paging_nav.html.erb +++ b/app/views/notes/_notes_paging_nav.html.erb @@ -23,14 +23,14 @@ <%= t(".next") %> <%= next_page_svg_tag :class => "flex-shrink-0" %> <% end %> - <% if @notes.size < @page_size %> -
  • - <%= tag.span next_link_content, :class => link_class %> -
  • - <% else %> + <% if @next_page %>
  • <%= link_to next_link_content, @params.merge(:page => @page + 1), :class => link_class %>
  • + <% else %> +
  • + <%= tag.span next_link_content, :class => link_class %> +
  • <% end %> diff --git a/test/system/user_notes_test.rb b/test/system/user_notes_test.rb new file mode 100644 index 000000000..04fa3838a --- /dev/null +++ b/test/system/user_notes_test.rb @@ -0,0 +1,45 @@ +require "application_system_test_case" + +class UserNotesTest < ApplicationSystemTestCase + test "boundary condition when next page link activates" do + user = create(:user) + ("A".."J").each do |x| + create(:note, :author => user, :description => "Note '#{x}'") do |note| + create(:note_comment, :event => "opened", :note => note, :author => user, :body => "Note '#{x}'") + end + end + + visit user_notes_path(user) + + within_content_body do + assert_text "Note 'J'" + assert_text "Note 'A'" + assert_no_link "Previous" + assert_no_link "Next" + end + + ("K".."K").each do |x| + create(:note, :author => user, :description => "Note '#{x}'") do |note| + create(:note_comment, :event => "opened", :note => note, :author => user, :body => "Note '#{x}'") + end + end + + visit user_notes_path(user) + + within_content_body do + assert_text "Note 'K'" + assert_text "Note 'B'" + assert_no_text "Note 'A'" + assert_no_link "Previous" + assert_link "Next" + + click_on "Next", :match => :first + + assert_no_text "Note 'K'" + assert_no_text "Note 'B'" + assert_text "Note 'A'" + assert_link "Previous" + assert_no_link "Next" + end + end +end -- 2.39.5