Skip to content

Commit ff23301

Browse files
joelhawksleyCopilot
andcommitted
Restore cached-template integration test
Since template caching is now decided at boot, with_template_caching also skips the template watcher hook the sandbox registered. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2e356ff-16cd-4517-8e63-a8600747d3fa
1 parent ac0a307 commit ff23301

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎test/sandbox/test/integration_test.rb‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def test_rendering_component_in_a_controller_with_block
5050
assert_response :success
5151
end
5252

53-
def test_template_changes_are_reflected_on_new_request_when_cache_template_loading_is_false
54-
with_new_cache do
53+
def test_template_changes_are_not_reflected_on_new_request_when_cache_template_loading_is_true
54+
with_template_caching do
5555
get "/controller_inline"
5656
assert_select("div", "bar")
5757
assert_response :success
5858

5959
modify_file "app/components/controller_inline_component.html.erb", "<div>Goodbye world!</div>" do
6060
get "/controller_inline"
61-
assert_select("div", "Goodbye world!")
61+
assert_select("div", "bar")
6262
assert_response :success
6363
end
6464

@@ -68,31 +68,22 @@ def test_template_changes_are_reflected_on_new_request_when_cache_template_loadi
6868
end
6969
end
7070

71-
def test_components_are_not_recompiled_on_new_request_when_no_template_changed
71+
def test_template_changes_are_reflected_on_new_request_when_cache_template_loading_is_false
7272
with_new_cache do
7373
get "/controller_inline"
74-
MyComponent.__vc_compile
75-
76-
get "/controller_inline"
74+
assert_select("div", "bar")
7775
assert_response :success
78-
assert MyComponent.__vc_compiled?
79-
end
80-
end
81-
82-
def test_components_are_recompiled_on_new_request_when_a_template_is_added
83-
new_template = Rails.root.join("app/components/added_template_component.html.erb")
8476

85-
with_new_cache do
86-
get "/controller_inline"
87-
MyComponent.__vc_compile
77+
modify_file "app/components/controller_inline_component.html.erb", "<div>Goodbye world!</div>" do
78+
get "/controller_inline"
79+
assert_select("div", "Goodbye world!")
80+
assert_response :success
81+
end
8882

89-
File.write(new_template, "<div>Added</div>")
9083
get "/controller_inline"
84+
assert_select("div", "bar")
9185
assert_response :success
92-
refute MyComponent.__vc_compiled?
9386
end
94-
ensure
95-
FileUtils.rm_f(new_template)
9687
end
9788

9889
def test_inherited_template_changes_are_reflected_on_new_request_when_cache_template_loading_is_false

‎test/test_helper.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,22 @@ def with_generate_sidecar(enabled, &block)
128128
with_generate_option(:sidecar, enabled, &block)
129129
end
130130

131+
# Template caching is decided at boot, so also skip the template watcher that
132+
# the sandbox registered because it boots without template caching.
131133
def with_template_caching
134+
executor = Rails.application.executor
135+
watcher_hook = executor._run_callbacks.find do |callback|
136+
callback.filter.is_a?(Proc) && callback.filter.source_location&.first&.end_with?("view_component/compile_cache.rb")
137+
end&.filter
138+
executor.skip_callback(:run, :before, watcher_hook) if watcher_hook
139+
132140
old_cache_template_loading = ActionView::Base.cache_template_loading
133141
ActionView::Base.cache_template_loading = true
134142

135143
yield
136144
ensure
137145
ActionView::Base.cache_template_loading = old_cache_template_loading
146+
executor.set_callback(:run, :before, watcher_hook) if watcher_hook
138147
end
139148

140149
def with_new_cache

0 commit comments

Comments
 (0)