1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix digesting templates with identical logical names when requesting a format other than the first default

This commit is contained in:
Javan Makhmali 2016-06-14 17:23:44 -04:00
parent 7980b31bc6
commit 2451177f37
3 changed files with 18 additions and 4 deletions

View file

@ -15,7 +15,7 @@ module ActionView
# * <tt>partial</tt> - Specifies whether the template is a partial
def digest(name:, finder:, dependencies: [])
dependencies ||= []
cache_key = ([ name ].compact + dependencies).join('.')
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join('.')
# this is a correctly done double-checked locking idiom
# (Concurrent::Map's lookups have volatile semantics)
@ -39,8 +39,11 @@ module ActionView
def tree(name, finder, partial = false, seen = {})
logical_name = name.gsub(%r|/_|, "/")
if finder.disable_cache { finder.exists?(logical_name, [], partial) }
template = finder.disable_cache { finder.find(logical_name, [], partial) }
format = finder.rendered_format
formats = finder.formats.without(format).unshift(format)
if finder.disable_cache { finder.exists?(logical_name, [], partial, [], formats: formats) }
template = finder.disable_cache { finder.find(logical_name, [], partial, [], formats: formats) }
if node = seen[template.identifier] # handle cycles in the tree
node

View file

@ -0,0 +1 @@
{"content": "Great story!"}

View file

@ -18,6 +18,7 @@ class FixtureFinder < ActionView::LookupContext
def initialize(details = {})
super(ActionView::PathSet.new(['digestor']), details, [])
@rendered_format = :html
end
end
@ -280,6 +281,12 @@ class TemplateDigestorTest < ActionView::TestCase
end
end
def test_different_formats
html_digest = digest("comments/_comment", format: :html)
json_digest = digest("comments/_comment", format: :json)
assert_not_equal html_digest, json_digest
end
private
def assert_logged(message)
@ -309,8 +316,11 @@ class TemplateDigestorTest < ActionView::TestCase
def digest(template_name, options = {})
options = options.dup
finder_options = options.extract!(:variants, :format)
finder.variants = finder_options[:variants] || []
finder.rendered_format = finder_options[:format] if finder_options[:format]
finder.variants = options.delete(:variants) || []
ActionView::Digestor.digest(name: template_name, finder: finder, dependencies: (options[:dependencies] || []))
end