From 2b43620e3c1352028f19550fcde4632d65cbd191 Mon Sep 17 00:00:00 2001
From: Pratik Naik <pratiknaik@gmail.com>
Date: Wed, 2 Jul 2008 16:38:50 +0100
Subject: Add :as option to render a collection of partials with a custom local
 variable name. [#509 state:resolved] [Simon Jefford, Pratik Naik]

---
 actionpack/test/controller/new_render_test.rb        | 9 +++++++++
 actionpack/test/fixtures/test/_customer_with_var.erb | 1 +
 actionpack/test/template/render_test.rb              | 5 +++++
 3 files changed, 15 insertions(+)
 create mode 100644 actionpack/test/fixtures/test/_customer_with_var.erb

(limited to 'actionpack/test')

diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index eac36a04cb..5a7da57559 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -152,6 +152,10 @@ class NewRenderTestController < ActionController::Base
     render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
   end
 
+  def partial_collection_with_as
+    render :partial => "customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer
+  end
+
   def partial_collection_with_spacer
     render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ]
   end
@@ -763,6 +767,11 @@ EOS
     assert_equal "Hello: davidHello: mary", @response.body
   end
 
+  def test_partial_collection_with_as
+    get :partial_collection_with_as
+    assert_equal "david david davidmary mary mary", @response.body
+  end
+
   def test_partial_collection_with_counter
     get :partial_collection_with_counter
     assert_equal "david0mary1", @response.body
diff --git a/actionpack/test/fixtures/test/_customer_with_var.erb b/actionpack/test/fixtures/test/_customer_with_var.erb
new file mode 100644
index 0000000000..3379246b7e
--- /dev/null
+++ b/actionpack/test/fixtures/test/_customer_with_var.erb
@@ -0,0 +1 @@
+<%= customer.name %> <%= object.name %> <%= customer_with_var.name %>
\ No newline at end of file
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 54e4bbda1b..64244e50f7 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -54,6 +54,11 @@ class ViewRenderTest < Test::Unit::TestCase
   def test_render_partial_collection
     assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
   end
+  
+  def test_render_partial_collection_as
+    assert_equal "david david davidmary mary mary", 
+      @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer)
+  end
 
   # TODO: The reason for this test is unclear, improve documentation
   def test_render_partial_and_fallback_to_layout
-- 
cgit v1.2.3