From fab5a817d05ea1fd4641c526ce5ef604f1b335fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fran=C3=A7a?= Date: Wed, 23 Jun 2021 13:59:09 -0400 Subject: [PATCH] Merge pull request #42437 from HParker/digest-find-parent-controller-template Use the lookup_context to find the correct template path --- .../metal/etag_with_template_digest.rb | 2 +- actionpack/test/controller/render_test.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/metal/etag_with_template_digest.rb b/actionpack/lib/action_controller/metal/etag_with_template_digest.rb index 983bd745bd7c2..6607ed009e3f1 100644 --- a/actionpack/lib/action_controller/metal/etag_with_template_digest.rb +++ b/actionpack/lib/action_controller/metal/etag_with_template_digest.rb @@ -44,7 +44,7 @@ def determine_template_etag(options) # template digest from the ETag. def pick_template_for_etag(options) unless options[:template] == false - options[:template] || "#{controller_path}/#{action_name}" + options[:template] || lookup_context.find_all(action_name, _prefixes).first&.virtual_path end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 6494f3cb5f6f6..6bf45863b407e 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -66,6 +66,12 @@ def hello_world end end +class InheritedRenderTestController < ImplicitRenderTestController + def hello_world + fresh_when(etag: "abc") + end +end + class TestController < ActionController::Base protect_from_forgery @@ -677,6 +683,28 @@ def test_etag_reflects_template_digest end end +class InheritedEtagRenderTest < ActionController::TestCase + tests InheritedRenderTestController + include TemplateModificationHelper + + def test_etag_reflects_template_digest + get :hello_world + assert_response :ok + assert_not_nil etag = @response.etag + + request.if_none_match = etag + get :hello_world + assert_response :not_modified + + modify_template("implicit_render_test/hello_world") do + request.if_none_match = etag + get :hello_world + assert_response :ok + assert_not_equal etag, @response.etag + end + end +end + class MetalRenderTest < ActionController::TestCase tests MetalTestController