Skip to content

Commit

Permalink
Merge pull request #32282 from javan/fix-digesting-mixed-formats
Browse files Browse the repository at this point in the history
Fix digesting templates with mixed formats
  • Loading branch information
javan committed Mar 20, 2018
1 parent 2a4a97b commit 0b53f57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions actionview/lib/action_view/digestor.rb
Expand Up @@ -45,11 +45,9 @@ def logger
# Create a dependency tree for template named +name+.
def tree(name, finder, partial = false, seen = {})
logical_name = name.gsub(%r|/_|, "/")
finder.formats = [finder.rendered_format] if finder.rendered_format

options = {}
options[:formats] = [finder.rendered_format] if finder.rendered_format

if template = finder.disable_cache { finder.find_all(logical_name, [], partial, [], options).first }
if template = finder.disable_cache { finder.find_all(logical_name, [], partial, []).first }
finder.rendered_format ||= template.formats.first

if node = seen[template.identifier] # handle cycles in the tree
Expand Down
1 change: 1 addition & 0 deletions actionview/test/fixtures/digestor/comments/show.js.erb
@@ -0,0 +1 @@
alert("<%=j render("comments/comment") %>")
12 changes: 12 additions & 0 deletions actionview/test/template/digestor_test.rb
Expand Up @@ -160,6 +160,18 @@ def test_template_formats_of_dependencies_with_same_logical_name_and_different_r
assert_equal [:html], tree_template_formats("messages/show").uniq
end

def test_template_dependencies_with_fallback_from_js_to_html_format
finder.rendered_format = :js
assert_equal ["comments/comment"], dependencies("comments/show")
end

def test_template_digest_with_fallback_from_js_to_html_format
finder.rendered_format = :js
assert_digest_difference("comments/show") do
change_template("comments/_comment")
end
end

def test_recursion_in_renders
assert digest("level/recursion") # assert recursion is possible
assert_not_nil digest("level/recursion") # assert digest is stored
Expand Down

0 comments on commit 0b53f57

Please sign in to comment.