Skip to content

Commit 9760d60

Browse files
committed
Update Turbo Drive <meta> across navigations
Closes [hotwired#549] Add System Test level coverage to ensure that Turbo Drive navigations will re-render any `<meta>` elements nested within the document's `<head>`. To achieve this coverage, introduce the `PagesController#show` action that links to HTML pages that render their `<head>` based on the `turbo_refresh_method` and `turbo_refresh_scroll` query parameters. [hotwired#549]: hotwired#549
1 parent 38a7ca6 commit 9760d60

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class PagesController < ApplicationController
2+
end
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= turbo_refreshes_with method: params.fetch(:turbo_refresh_method, :replace).to_sym, scroll: params.fetch(:turbo_refresh_scroll, :reset).to_sym %>
2+
3+
<h1><%= params[:id].titleize %></h1>
4+
5+
<% {
6+
classic: {
7+
turbo_refresh_method: :replace,
8+
turbo_refresh_scroll: :reset,
9+
},
10+
morph: {
11+
turbo_refresh_method: :morph,
12+
turbo_refresh_scroll: :preserve,
13+
}
14+
}.each do |id, refresh| %>
15+
<%= link_to_unless_current id.to_s.titleize, page_path(id, refresh) %>
16+
<% end %>

test/dummy/config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Rails.application.routes.draw do
2+
resources :pages, only: :show
23
resources :articles do
34
delete :destroy_all, on: :collection
45
end

test/system/navigations_test.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require "application_system_test_case"
2+
3+
class NavigationsTest < ApplicationSystemTestCase
4+
test "navigation updates Turbo Refresh meta tags" do
5+
visit page_path(:classic)
6+
7+
within "head", visible: false do
8+
assert_selector :element, "meta", name: "turbo-refresh-method", content: "replace", visible: false, count: 1
9+
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "reset", visible: false, count: 1
10+
end
11+
12+
click_link "Morph"
13+
14+
within "head", visible: false do
15+
assert_selector :element, "meta", name: "turbo-refresh-method", content: "morph", visible: false, count: 1
16+
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "preserve", visible: false, count: 1
17+
end
18+
19+
click_link "Classic"
20+
21+
within "head", visible: false do
22+
assert_selector :element, "meta", name: "turbo-refresh-method", content: "replace", visible: false, count: 1
23+
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "reset", visible: false, count: 1
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)