Skip to content

Commit

Permalink
Merge pull request #42437 from HParker/digest-find-parent-controller-…
Browse files Browse the repository at this point in the history
…template

Use the lookup_context to find the correct template path
  • Loading branch information
rafaelfranca committed Jun 23, 2021
2 parents 9496a74 + 26259b0 commit ec69356
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ec69356

Please sign in to comment.