Skip to content

Commit fab5a81

Browse files
committed
Merge pull request #42437 from HParker/digest-find-parent-controller-template
Use the lookup_context to find the correct template path
1 parent 08b2994 commit fab5a81

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

actionpack/lib/action_controller/metal/etag_with_template_digest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def determine_template_etag(options)
4444
# template digest from the ETag.
4545
def pick_template_for_etag(options)
4646
unless options[:template] == false
47-
options[:template] || "#{controller_path}/#{action_name}"
47+
options[:template] || lookup_context.find_all(action_name, _prefixes).first&.virtual_path
4848
end
4949
end
5050

actionpack/test/controller/render_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def hello_world
6666
end
6767
end
6868

69+
class InheritedRenderTestController < ImplicitRenderTestController
70+
def hello_world
71+
fresh_when(etag: "abc")
72+
end
73+
end
74+
6975
class TestController < ActionController::Base
7076
protect_from_forgery
7177

@@ -677,6 +683,28 @@ def test_etag_reflects_template_digest
677683
end
678684
end
679685

686+
class InheritedEtagRenderTest < ActionController::TestCase
687+
tests InheritedRenderTestController
688+
include TemplateModificationHelper
689+
690+
def test_etag_reflects_template_digest
691+
get :hello_world
692+
assert_response :ok
693+
assert_not_nil etag = @response.etag
694+
695+
request.if_none_match = etag
696+
get :hello_world
697+
assert_response :not_modified
698+
699+
modify_template("implicit_render_test/hello_world") do
700+
request.if_none_match = etag
701+
get :hello_world
702+
assert_response :ok
703+
assert_not_equal etag, @response.etag
704+
end
705+
end
706+
end
707+
680708
class MetalRenderTest < ActionController::TestCase
681709
tests MetalTestController
682710

0 commit comments

Comments
 (0)