Fix back navigation from activity page to cards (#2727)

Three changes needed to support navigating back from a card to the
activity page:

- Add root_path to the prefer_referrer allowlist on the card show page
- Switch event links from HTML target="_top" to data-turbo-frame="_top"
  so Turbo handles the navigation and turbo:before-visit fires to save
  the referrer
- Normalize trailing slashes in the referrer path comparison so
  /account_id and /account_id/ both match

ref: https://app.fizzy.do/5986089/cards/2390
This commit is contained in:
Mike Dalessio
2026-03-18 22:03:36 -04:00
committed by GitHub
parent 248fc5d3e7
commit 11df9c3589
4 changed files with 29 additions and 4 deletions
+24
View File
@@ -26,6 +26,30 @@ class BackLinkNavigationTest < ApplicationSystemTestCase
assert_current_path filter_url, ignore_query: false
end
test "card back link returns to activity page when navigating from it" do
sign_in_as(users(:david))
assert_text "Layout is broken"
click_on "Layout is broken"
assert_selector "a.btn--back strong", text: "Back to Home"
find("a.btn--back").click
assert_current_path root_path
end
test "card back link returns to activity page when navigating from it without trailing slash" do
sign_in_as(users(:david))
activity_url_without_trailing_slash = root_url.chomp("/")
visit activity_url_without_trailing_slash
assert_text "Layout is broken"
click_on "Layout is broken"
assert_selector "a.btn--back strong", text: "Back to Home"
find("a.btn--back").click
assert_current_path activity_url_without_trailing_slash
end
test "card back link is not rewritten when navigating from a non-filter page" do
sign_in_as(users(:david))