From 2451177f37aa252513ac372d24cba6a3c44c054b Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Tue, 14 Jun 2016 17:23:44 -0400 Subject: Fix digesting templates with identical logical names when requesting a format other than the first default --- actionview/lib/action_view/digestor.rb | 9 ++++++--- actionview/test/fixtures/digestor/comments/_comment.json.erb | 1 + actionview/test/template/digestor_test.rb | 12 +++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 actionview/test/fixtures/digestor/comments/_comment.json.erb (limited to 'actionview') diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index b91e61da18..bc42b5dae1 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -15,7 +15,7 @@ module ActionView # * partial - 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 diff --git a/actionview/test/fixtures/digestor/comments/_comment.json.erb b/actionview/test/fixtures/digestor/comments/_comment.json.erb new file mode 100644 index 0000000000..696eb13917 --- /dev/null +++ b/actionview/test/fixtures/digestor/comments/_comment.json.erb @@ -0,0 +1 @@ +{"content": "Great story!"} diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 4750d2a5a3..3dad70f464 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -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 -- cgit v1.2.3