From 0da2aa6d11b6cb8433a12a6707355cc15506583a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 2 Feb 2008 06:16:04 +0000 Subject: Introduce the :index option for form_for and fields_for to simplify multi-model forms (see http://railscasts.com/episodes/75). Closes #9883. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8786 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/template/form_helper_test.rb | 78 +++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index a3dff7ec52..b788a9e2f9 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -363,14 +363,14 @@ class FormHelperTest < Test::Unit::TestCase def test_form_for_with_index _erbout = '' - + form_for("post[]", @post) do |f| _erbout.concat f.label(:title) _erbout.concat f.text_field(:title) _erbout.concat f.text_area(:body) _erbout.concat f.check_box(:secret) end - + expected = "
" + "" + @@ -383,6 +383,26 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end + def test_form_for_with_nil_index_option_override + _erbout = '' + + form_for("post[]", @post, :index => nil) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "" + + "" + + "" + + "" + + "" + + "
" + + assert_dom_equal expected, _erbout + end + def test_nested_fields_for _erbout = '' form_for(:post, @post) do |f| @@ -416,6 +436,60 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end + def test_fields_for_with_index + _erbout = '' + + fields_for("post[]", @post) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "" + + "" + + "" + + "" + + assert_dom_equal expected, _erbout + end + + def test_fields_for_with_nil_index_option_override + _erbout = '' + + fields_for("post[]", @post, :index => nil) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "" + + "" + + "" + + "" + + assert_dom_equal expected, _erbout + end + + def test_fields_for_with_index_option_override + _erbout = '' + + fields_for("post[]", @post, :index => "abc") do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "" + + "" + + "" + + "" + + assert_dom_equal expected, _erbout + end + def test_fields_for_without_object _erbout = '' fields_for(:post) do |f| -- cgit v1.2.3