Add partial iteration variable to template keys

When rendering heterogeneous collection using `render @collection` or
`render partial: @collection`, the expected `<partial_name>_iteration`
variable is missing due to `find_template` not having the name of the
iteration variable included in its cache keys.
This commit is contained in:
Matthew Eagar 2017-01-24 20:40:34 -05:00
parent 6363fa1a6f
commit e524327e51
4 changed files with 12 additions and 1 deletions

View File

@ -458,7 +458,7 @@ module ActionView
locals[counter] = index
locals[iteration] = partial_iteration
template = (cache[path] ||= find_template(path, keys + [as, counter]))
template = (cache[path] ||= find_template(path, keys + [as, counter, iteration]))
content = template.render(view, locals)
partial_iteration.iterate!
content

View File

@ -0,0 +1 @@
<%= defined?(partial_iteration_1_iteration) %>

View File

@ -0,0 +1 @@
<%= defined?(partial_iteration_2_iteration) -%>

View File

@ -301,6 +301,15 @@ module RenderTestCases
@view.render(partial: "test/local_inspector", collection: [ Customer.new("mary") ])
end
def test_render_partial_collection_with_different_partials_still_provides_partial_iteration
a = {}
b = {}
def a.to_partial_path; "test/partial_iteration_1"; end
def b.to_partial_path; "test/partial_iteration_2"; end
assert_equal "local-variable\nlocal-variable", @controller_view.render([a, b])
end
def test_render_partial_with_empty_collection_should_return_nil
assert_nil @view.render(partial: "test/customer", collection: [])
end