aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2016-06-14 17:23:44 -0400
committerJavan Makhmali <javan@javan.us>2016-06-15 18:25:18 -0400
commit2451177f37aa252513ac372d24cba6a3c44c054b (patch)
tree92dc144312995a07a49062ba5d12b2914518402d /actionview
parent7980b31bc6dd123a0635f470998362a602b66e25 (diff)
downloadrails-2451177f37aa252513ac372d24cba6a3c44c054b.tar.gz
rails-2451177f37aa252513ac372d24cba6a3c44c054b.tar.bz2
rails-2451177f37aa252513ac372d24cba6a3c44c054b.zip
Fix digesting templates with identical logical names when requesting a format other than the first default
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/digestor.rb9
-rw-r--r--actionview/test/fixtures/digestor/comments/_comment.json.erb1
-rw-r--r--actionview/test/template/digestor_test.rb12
3 files changed, 18 insertions, 4 deletions
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
# * <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
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