@@ -27,7 +27,13 @@ def setup
2727 :body => "Write entire text here" ,
2828 :color => {
2929 :red => "Rojo"
30+ } ,
31+ :comments => {
32+ :body => "Write body here"
3033 }
34+ } ,
35+ :tag => {
36+ :value => "Tag"
3137 }
3238 }
3339 }
@@ -68,6 +74,12 @@ def @post.to_param; '123'; end
6874 @post . secret = 1
6975 @post . written_on = Date . new ( 2004 , 6 , 15 )
7076
77+ @post . comments = [ ]
78+ @post . comments << @comment
79+
80+ @post . tags = [ ]
81+ @post . tags << Tag . new
82+
7183 @blog_post = Blog ::Post . new ( "And his name will be forty and four." , 44 )
7284 end
7385
@@ -151,6 +163,40 @@ def test_label_with_locales_and_value
151163 I18n . locale = old_locale
152164 end
153165
166+ def test_label_with_locales_and_nested_attributes
167+ old_locale , I18n . locale = I18n . locale , :label
168+ form_for ( @post , :html => { :id => 'create-post' } ) do |f |
169+ f . fields_for ( :comments ) do |cf |
170+ concat cf . label ( :body )
171+ end
172+ end
173+
174+ expected = whole_form ( "/posts/123" , "create-post" , "edit_post" , :method => "put" ) do
175+ "<label for=\" post_comments_attributes_0_body\" >Write body here</label>"
176+ end
177+
178+ assert_dom_equal expected , output_buffer
179+ ensure
180+ I18n . locale = old_locale
181+ end
182+
183+ def test_label_with_locales_fallback_and_nested_attributes
184+ old_locale , I18n . locale = I18n . locale , :label
185+ form_for ( @post , :html => { :id => 'create-post' } ) do |f |
186+ f . fields_for ( :tags ) do |cf |
187+ concat cf . label ( :value )
188+ end
189+ end
190+
191+ expected = whole_form ( "/posts/123" , "create-post" , "edit_post" , :method => "put" ) do
192+ "<label for=\" post_tags_attributes_0_value\" >Tag</label>"
193+ end
194+
195+ assert_dom_equal expected , output_buffer
196+ ensure
197+ I18n . locale = old_locale
198+ end
199+
154200 def test_label_with_for_attribute_as_symbol
155201 assert_dom_equal ( '<label for="my_for">Title</label>' , label ( :post , :title , nil , :for => "my_for" ) )
156202 end
0 commit comments