Merge pull request #23582 from opf/bug/stc-811-documents-pagination-breaks-upon-filtering-the-list

[STC-811] Fix pagination for filtered Documents & Reserved identifiers
This commit is contained in:
Kabiru Mwenja
2026-06-09 14:32:29 +03:00
committed by GitHub
6 changed files with 41 additions and 3 deletions
@@ -47,5 +47,7 @@ module Admin::Settings::ProjectReservedIdentifiers
def blank_title = t("admin.reserved_identifiers.empty_heading")
def blank_description = t("admin.reserved_identifiers.empty_body")
def blank_icon = :"check-circle"
def pagination_params = { params: { action: "index" } }
end
end
@@ -140,5 +140,5 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<% if paginated? %>
<%= helpers.pagination_links_full rows %>
<%= helpers.pagination_links_full rows, **pagination_params %>
<% end %>
@@ -77,6 +77,8 @@ module OpPrimer
self.class.main_column.include?(column)
end
def pagination_params = {}
def column_title(name)
_, header_options = headers.assoc(name)
header_options&.dig(:caption)
@@ -56,7 +56,7 @@
end
component.with_row(py: 0) do
helpers.pagination_links_full(documents)
helpers.pagination_links_full(documents, params: { action: "index" })
end
end
else
@@ -214,6 +214,22 @@ RSpec.describe DocumentsController do
end
end
describe "#search", with_settings: { per_page_options: "1 5 10" } do
let!(:document2) { create(:document, title: "Second Document", project:, type: document_type) }
it "returns a turbo_stream response" do
get :search, params: { project_id: project.identifier, per_page: 1 }, format: :turbo_stream
expect(response).to have_http_status(:ok)
end
it "renders pagination links that target the index action, not the search action" do
get :search, params: { project_id: project.identifier, per_page: 1 }, format: :turbo_stream
expect(response.body).not_to include("#{search_project_documents_path(project)}?")
end
end
describe "#render_avatars" do
let(:user) { create(:user, member_with_permissions: { project => [:view_documents] }) }
let!(:non_member) { create(:user) }
@@ -73,13 +73,31 @@ RSpec.describe Admin::Settings::ProjectReservedIdentifiersController do
end
end
describe "GET #search", with_settings: { work_packages_identifier: "classic" } do
describe "GET #search", with_settings: { work_packages_identifier: "classic", per_page_options: "1 5 10" } do
render_views
it "responds with turbo stream" do
get :search, format: :turbo_stream
expect(response).to have_http_status(:ok)
expect(response.media_type).to eq("text/vnd.turbo-stream.html")
end
context "with multiple reserved slugs triggering pagination" do
let!(:project1) { create(:project, identifier: "proj-a") }
let!(:project2) { create(:project, identifier: "proj-b") }
before do
FriendlyId::Slug.create!(sluggable: project1, slug: "old-a")
FriendlyId::Slug.create!(sluggable: project2, slug: "old-b")
end
it "renders pagination links that target the index action, not the search action (regression #STC-811)" do
get :search, params: { per_page: 1 }, format: :turbo_stream
expect(response.body).not_to include("#{search_admin_settings_project_reserved_identifiers_path}?")
end
end
context "with a reserved slug" do
let!(:project) { create(:project, identifier: "current-id") }