aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/form_helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template/form_helper_test.rb')
-rw-r--r--actionpack/test/template/form_helper_test.rb117
1 files changed, 114 insertions, 3 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 2234fbece9..d1e1338a17 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -139,6 +139,10 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great title"))
end
+ def test_label_with_block
+ assert_dom_equal('<label for="post_title">The title, please:</label>', label(:post, :title) { "The title, please:" })
+ end
+
def test_text_field
assert_dom_equal(
'<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
@@ -419,6 +423,90 @@ class FormHelperTest < ActionView::TestCase
check_box("post", "secret", :id => "i mean it")
end
+ def test_nil_id
+ assert_dom_equal(
+ '<input name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => nil)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "id" => nil)
+ )
+ assert_dom_equal(
+ '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" name="post[secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", "id" => nil)
+ )
+ assert_dom_equal(
+ '<input type="radio" name="post[secret]" value="0" />',
+ radio_button("post", "secret", "0", "id" => nil)
+ )
+ assert_dom_equal(
+ '<select name="post[secret]"></select>',
+ select("post", "secret", [], {}, "id" => nil)
+ )
+ assert_dom_equal text_field("post", "title", "id" => nil),
+ text_field("post", "title", :id => nil)
+ assert_dom_equal text_area("post", "body", "id" => nil),
+ text_area("post", "body", :id => nil)
+ assert_dom_equal check_box("post", "secret", "id" => nil),
+ check_box("post", "secret", :id => nil)
+ assert_dom_equal radio_button("post", "secret", "0", "id" => nil),
+ radio_button("post", "secret", "0", :id => nil)
+ end
+
+ def test_index
+ assert_dom_equal(
+ '<input name="post[5][title]" size="30" id="post_5_title" type="text" value="Hello World" />',
+ text_field("post", "title", "index" => 5)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[5][body]" id="post_5_body" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "index" => 5)
+ )
+ assert_dom_equal(
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" id="post_5_secret" />',
+ check_box("post", "secret", "index" => 5)
+ )
+ assert_dom_equal(
+ text_field("post", "title", "index" => 5),
+ text_field("post", "title", "index" => 5)
+ )
+ assert_dom_equal(
+ text_area("post", "body", "index" => 5),
+ text_area("post", "body", "index" => 5)
+ )
+ assert_dom_equal(
+ check_box("post", "secret", "index" => 5),
+ check_box("post", "secret", "index" => 5)
+ )
+ end
+
+ def test_index_with_nil_id
+ assert_dom_equal(
+ '<input name="post[5][title]" size="30" type="text" value="Hello World" />',
+ text_field("post", "title", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ '<textarea cols="40" name="post[5][body]" rows="20">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ '<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" />',
+ check_box("post", "secret", "index" => 5, 'id' => nil)
+ )
+ assert_dom_equal(
+ text_field("post", "title", "index" => 5, 'id' => nil),
+ text_field("post", "title", :index => 5, :id => nil)
+ )
+ assert_dom_equal(
+ text_area("post", "body", "index" => 5, 'id' => nil),
+ text_area("post", "body", :index => 5, :id => nil)
+ )
+ assert_dom_equal(
+ check_box("post", "secret", "index" => 5, 'id' => nil),
+ check_box("post", "secret", :index => 5, :id => nil)
+ )
+ end
+
def test_auto_index
pid = @post.id
assert_dom_equal(
@@ -445,10 +533,33 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_auto_index_with_nil_id
+ pid = @post.id
+ assert_dom_equal(
+ "<input name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />",
+ text_field("post[]","title", :id => nil)
+ )
+ assert_dom_equal(
+ "<textarea cols=\"40\" name=\"post[#{pid}][body]\" rows=\"20\">Back to the hill and over it again!</textarea>",
+ text_area("post[]", "body", :id => nil)
+ )
+ assert_dom_equal(
+ "<input name=\"post[#{pid}][secret]\" type=\"hidden\" value=\"0\" /><input checked=\"checked\" name=\"post[#{pid}][secret]\" type=\"checkbox\" value=\"1\" />",
+ check_box("post[]", "secret", :id => nil)
+ )
+ assert_dom_equal(
+"<input checked=\"checked\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Hello World\" />",
+ radio_button("post[]", "title", "Hello World", :id => nil)
+ )
+ assert_dom_equal("<input name=\"post[#{pid}][title]\" type=\"radio\" value=\"Goodbye World\" />",
+ radio_button("post[]", "title", "Goodbye World", :id => nil)
+ )
+ end
+
def test_form_for
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
- concat f.label(:title)
+ concat f.label(:title) { "The Title" }
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@@ -458,7 +569,7 @@ class FormHelperTest < ActionView::TestCase
expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
- "<label for='post_title'>Title</label>" +
+ "<label for='post_title'>The Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -485,7 +596,7 @@ class FormHelperTest < ActionView::TestCase
"<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />" +
"<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='other_name[secret]' value='0' type='hidden' />" +
- "<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
+ "<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
"<input name='commit' id='other_name_submit' value='Create post' type='submit' /></form>"
assert_dom_equal expected, output_buffer