From 26259b06601f88ef52c6e05617e650caf44d8748 Mon Sep 17 00:00:00 2001 From: HParker Date: Wed, 9 Jun 2021 11:51:15 -0700 Subject: [PATCH] Use the lookup_context to find the correct template path This replaces the controller/action method of finding a path with the lookup_context which should always find the same thing as the render method finds. --- .../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 54fa5dd8cb0c5..768baed4184f3 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -65,6 +65,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 @@ -724,6 +730,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