Skip to content

Commit

Permalink
Fix digesting templates with identical logical names when requesting …
Browse files Browse the repository at this point in the history
…a format other than the first default
  • Loading branch information
javan committed Jun 15, 2016
1 parent 7980b31 commit 2451177
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 6 additions & 3 deletions actionview/lib/action_view/digestor.rb
Expand Up @@ -15,7 +15,7 @@ class << self
# * <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)
Expand All @@ -39,8 +39,11 @@ def logger
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
Expand Down
@@ -0,0 +1 @@
{"content": "Great story!"}
12 changes: 11 additions & 1 deletion actionview/test/template/digestor_test.rb
Expand Up @@ -18,6 +18,7 @@ class FixtureFinder < ActionView::LookupContext

def initialize(details = {})
super(ActionView::PathSet.new(['digestor']), details, [])
@rendered_format = :html
end
end

Expand Down Expand Up @@ -280,6 +281,12 @@ def test_digest_cache_cleanup_with_recursion_and_template_caching_off
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)
Expand Down Expand Up @@ -309,8 +316,11 @@ def assert_digest_difference(template_name, options = {})

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

Expand Down

0 comments on commit 2451177

Please sign in to comment.