From 267d3964ebd7bbc8879d69ff5a323527179c497d Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 2 Jul 2008 17:19:41 +0100 Subject: [PATCH] Make sure render :collection doesnt set nil local when :as is absent --- actionpack/lib/action_view/partial_template.rb | 3 ++- actionpack/test/fixtures/test/_local_inspector.html.erb | 1 + actionpack/test/template/render_test.rb | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 actionpack/test/fixtures/test/_local_inspector.html.erb diff --git a/actionpack/lib/action_view/partial_template.rb b/actionpack/lib/action_view/partial_template.rb index 3513244ecb..a2129952c0 100644 --- a/actionpack/lib/action_view/partial_template.rb +++ b/actionpack/lib/action_view/partial_template.rb @@ -23,7 +23,8 @@ module ActionView #:nodoc: end def render_member(object) - @locals[:object] = @locals[@variable_name] = @locals[as] = object + @locals[:object] = @locals[@variable_name] = object + @locals[as] = object if as template = render_template @locals[@counter_name] += 1 diff --git a/actionpack/test/fixtures/test/_local_inspector.html.erb b/actionpack/test/fixtures/test/_local_inspector.html.erb new file mode 100644 index 0000000000..c5a6e3e5bc --- /dev/null +++ b/actionpack/test/fixtures/test/_local_inspector.html.erb @@ -0,0 +1 @@ +<%= local_assigns.keys.map(&:to_s).sort.join(",") -%> \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 64244e50f7..5163c35189 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -59,6 +59,11 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "david david davidmary mary mary", @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer) end + + def test_render_partial_collection_without_as + assert_equal "local_inspector,local_inspector_counter,object", + @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ]) + end # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout