Skip to content

Commit 510e36c

Browse files
joelhawksleyCopilot
andcommitted
Recompile components after modify_file to prevent test pollution
The integration test rendered CacheableComponent inside a modify_file block, which compiles a render_template_for method with the modified template source directly onto the component class. Restoring the file via modify_file's ensure did not undo that method redefinition, so subsequent tests that rendered CacheableComponent kept seeing the temporarily-modified output ('changed'). Invalidating the CompileCache after modify_file restores the file forces the next render to recompile from the restored source, isolating the modification to the block that requested it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent f8f987c commit 510e36c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎test/test_helper.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def modify_file(file, content)
165165
yield
166166
ensure
167167
File.open(filename, "wb+") { |f| f.write(old_content) }
168+
# A component that rendered while `file` was modified had its
169+
# `render_template_for` method defined against the modified source. That
170+
# method stays on the class until the compiler runs again, so invalidate
171+
# every compiled component's cache entry: the next render of any of them
172+
# recompiles from the now-restored file.
173+
ViewComponent::CompileCache.invalidate!
168174
end
169175
end
170176

0 commit comments

Comments
 (0)