1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

partial counters with :as [#2804 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Jeff Kreeftmeijer 2010-05-15 13:25:48 +02:00 committed by Jeremy Kemper
parent 3436fdfc12
commit fa99de0bd0
3 changed files with 11 additions and 0 deletions

View file

@ -248,6 +248,7 @@ module ActionView
@collection.each do |object|
locals[counter_name] += 1
locals["#{as.to_s}_counter".to_sym] = locals[counter_name]
locals[as] = object
segments << template.render(@view, locals)

View file

@ -547,6 +547,10 @@ class TestController < ActionController::Base
render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
end
def partial_collection_with_as_and_counter
render :partial => "customer_counter_with_as", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :client
end
def partial_collection_with_locals
render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
end
@ -1242,6 +1246,11 @@ class RenderTest < ActionController::TestCase
assert_equal "david0mary1", @response.body
end
def test_partial_collection_with_as_and_counter
get :partial_collection_with_as_and_counter
assert_equal "david0mary1", @response.body
end
def test_partial_collection_with_locals
get :partial_collection_with_locals
assert_equal "Bonjour: davidBonjour: mary", @response.body

View file

@ -0,0 +1 @@
<%= client.name %><%= client_counter %>