From 7fadb3f261fc7cc753d303d0fbe2cbf019385f99 Mon Sep 17 00:00:00 2001 From: Will Read Date: Wed, 7 Oct 2009 18:47:26 -0700 Subject: Allow explicit placement of hidden id element for nested models. [#3259 state:resolved] Signed-off-by: Eloy Duran --- actionpack/test/template/form_helper_test.rb | 66 +++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 11 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 04c635e770..44734abb18 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -611,6 +611,26 @@ class FormHelperTest < ActionView::TestCase end end + expected = '
' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement + @post.author = Author.new(321) + + form_for(:post, @post) do |f| + concat f.text_field(:title) + f.fields_for(:author) do |af| + concat af.hidden_field(:id) + concat af.text_field(:name) + end + end + expected = '
' + '' + '' + @@ -632,6 +652,30 @@ class FormHelperTest < ActionView::TestCase end end + expected = '' + + '' + + '' + + '' + + '' + + '' + + '
' + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_explicit_hidden_field_placement + @post.comments = Array.new(2) { |id| Comment.new(id + 1) } + + form_for(:post, @post) do |f| + concat f.text_field(:title) + @post.comments.each do |comment| + f.fields_for(:comments, comment) do |cf| + concat cf.hidden_field(:id) + concat cf.text_field(:name) + end + end + end + expected = '
' + '' + '' + @@ -678,8 +722,8 @@ class FormHelperTest < ActionView::TestCase expected = '' + '' + - '' + '' + + '' + '' + '
' @@ -713,10 +757,10 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + '' + - '' + + '' + '' + + '' + '
' assert_dom_equal expected, output_buffer @@ -736,8 +780,8 @@ class FormHelperTest < ActionView::TestCase expected = '
' + '' + - '' + '' + + '' + '' + '
' @@ -755,8 +799,8 @@ class FormHelperTest < ActionView::TestCase end expected = '
' + - '' + '' + + '' + '
' assert_dom_equal expected, output_buffer @@ -790,18 +834,18 @@ class FormHelperTest < ActionView::TestCase end expected = '
' + - '' + '' + - '' + '' + - '' + + '' + + '' + '' + - '' + '' + - '' + + '' + + '' + '' + - '' + '' + + '' + + '' + '
' assert_dom_equal expected, output_buffer -- cgit v1.2.3