diff options
author | Rusty Geldmacher <rgeldmacher@sermo.com> | 2012-07-10 12:14:06 -0400 |
---|---|---|
committer | Rusty Geldmacher <rgeldmacher@sermo.com> | 2012-07-10 12:14:06 -0400 |
commit | 27c8debdc6b242c845a279187205a2b057e18469 (patch) | |
tree | 731581a94a3c8eb449c6ed59b5c67683bfb29217 /actionpack/test | |
parent | 45d78a3dd1a1b199d4d3a953d3cef01de47432f6 (diff) | |
download | rails-27c8debdc6b242c845a279187205a2b057e18469.tar.gz rails-27c8debdc6b242c845a279187205a2b057e18469.tar.bz2 rails-27c8debdc6b242c845a279187205a2b057e18469.zip |
Fixed bug creating invalid HTML in select options
When a select tag is created for a field with errors, and that select
tag has :prompt or :include_blank options, then the inserted first
option will errantly have a <div class="field_with_errors"> wrapping
it.
See https://github.com/rails/rails/issues/7017
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/active_model_helper_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb index 66a7bce71e..058db29645 100644 --- a/actionpack/test/template/active_model_helper_test.rb +++ b/actionpack/test/template/active_model_helper_test.rb @@ -41,6 +41,19 @@ class ActiveModelHelperTest < ActionView::TestCase ) end + def test_select_with_errors + assert_dom_equal( + %(<div class="field_with_errors"><select name="post[author_name]" id="post_author_name"><option value="a">a</option>\n<option value="b">b</option></select></div>), + select("post", "author_name", [:a, :b]) + ) + end + + def test_select_with_errors_and_blank_option + expected_dom = %(<div class="field_with_errors"><select name="post[author_name]" id="post_author_name"><option value="">Choose one...</option>\n<option value="a">a</option>\n<option value="b">b</option></select></div>) + assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :include_blank => 'Choose one...')) + assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :prompt => 'Choose one...')) + end + def test_date_select_with_errors assert_dom_equal( %(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="15" />\n</div>), |