diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index a38e3c6728..6cc4b50d67 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -234,6 +234,10 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end + def test_form_builder_does_not_have_form_for_method + assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for') + end + def test_form_for_and_fields_for _erbout = '' @@ -256,4 +260,75 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end + + class LabellingBulider < ActionView::Helpers::FormBuilder + (field_helpers - %w(hidden_field)).each do |selector| + src = <<-END_SRC + def #{selector}(field, *args, &proc) + "<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>" + end + END_SRC + class_eval src, __FILE__, __LINE__ + end + end + + def test_form_for_with_labelled_builder + _erbout = '' + + form_for(:post, @post, :builder => LabellingBulider) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "<form action='http://www.example.com' method='post'>" + + "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" + + "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" + + "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + + "<input name='post[secret]' type='hidden' value='0' /><br/>" + + "</form>" + + assert_dom_equal expected, _erbout + end + + # Perhaps this test should be moved to prototype helper tests. + def test_remote_form_for_with_labelled_builder + self.extend ActionView::Helpers::PrototypeHelper + _erbout = '' + + remote_form_for(:post, @post, :builder => LabellingBulider) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "<form action='http://www.example.com' method='post'>" + + "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" + + "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" + + "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + + "<input name='post[secret]' type='hidden' value='0' /><br/>" + + "</form>" + + assert_dom_equal expected, _erbout + end + + def test_fields_for_with_labelled_builder + _erbout = '' + + fields_for(:post, @post, :builder => LabellingBulider) do |f| + _erbout.concat f.text_field(:title) + _erbout.concat f.text_area(:body) + _erbout.concat f.check_box(:secret) + end + + expected = + "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" + + "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" + + "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + + "<input name='post[secret]' type='hidden' value='0' /><br/>" + + assert_dom_equal expected, _erbout + end end |