diff options
author | Rafael Mendonça França <rafael.franca@plataformatec.com.br> | 2012-05-13 00:41:26 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-13 01:00:31 -0300 |
commit | 94d84c5383fd2394577a286738e9d9663c6b8f29 (patch) | |
tree | 3dd2e81f5c56b5cfd456edbf0216046e75562e0e /actionpack | |
parent | a8cfaed3389de8c12ad8c8e363df13bd93354ab4 (diff) | |
download | rails-94d84c5383fd2394577a286738e9d9663c6b8f29.tar.gz rails-94d84c5383fd2394577a286738e9d9663c6b8f29.tar.bz2 rails-94d84c5383fd2394577a286738e9d9663c6b8f29.zip |
`:include_blank` should be true if the size option is nil
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/base.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 36 |
3 files changed, 25 insertions, 17 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b731fceb97..a49e54d3fd 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,6 +1,6 @@ ## Rails 4.0.0 (unreleased) ## -* The `select` method (select tag) forces :include_blank if `required` is true and +* The `select` method (select tag) forces :include_blank if `required` is true and `display size` is one and `multiple` is not true. *Angelo Capilleri* * Copy literal route constraints to defaults so that url generation know about them. diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index bf209d3a20..74a9e043c0 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -130,9 +130,9 @@ module ActionView select end end - + def option_required?(html_options) - html_options["required"] && html_options["size"].to_i == 1 && !html_options["multiple"] + html_options["required"] && !html_options["multiple"] && !(html_options["size"].to_i > 1) end def add_options(option_tags, options, value = nil) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 8b3a51bc6d..52b4939670 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -633,28 +633,36 @@ class FormOptionsHelperTest < ActionView::TestCase select("post", "category", [nil, "othervalue"]) ) end - - def test_select_with_included_and_display_size_equals_to_one + + def test_required_select + assert_dom_equal( + %(<select id="post_category" name="post[category]" required="required"><option value=""></option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>), + select("post", "category", %w(abe mus hest), {}, required: true) + ) + end + end + + def test_required_select_display_size_equals_to_one assert_dom_equal( - "<select id=\"post_category\" name=\"post[category]\" required=\"required\" size=\"1\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"mus\">mus</option>\n<option value=\"hest\">hest</option></select>", - select("post", "category", %w( abe mus hest),{}, :required => true, :size => 1) + %(<select id="post_category" name="post[category]" required="required" size="1"><option value=""></option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>), + select("post", "category", %w(abe mus hest), {}, required: true, size: 1) ) end - - def test_select_with_included_and_display_size_no_equals_to_one - assert_dom_equal( - "<select id=\"post_category\" name=\"post[category]\" required=\"required\" size=\"2\"><option value=\"abe\">abe</option>\n<option value=\"mus\">mus</option>\n<option value=\"hest\">hest</option></select>", - select("post", "category", %w( abe mus hest),{}, :required => true, :size => 2) - ) + + def test_required_select_with_display_size_bigger_than_one + assert_dom_equal( + %(<select id="post_category" name="post[category]" required="required" size="2"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>), + select("post", "category", %w(abe mus hest), {}, required: true, size: 2) + ) end - def test_select_with_included_and_multiple + def test_required_select_with_multiple_option assert_dom_equal( - "<input name=\"post[category][]\" type=\"hidden\" value=\"\"/><select id=\"post_category\" multiple=\"multiple\" name=\"post[category][]\" required=\"required\" size=\"1\"><option value=\"abe\">abe</option>\n<option value=\"mus\">mus</option>\n<option value=\"hest\">hest</option></select>", - select("post", "category", %w( abe mus hest), {}, :required => true, :size => 1, :multiple => true) + %(<input name="post[category][]" type="hidden" value=""/><select id="post_category" multiple="multiple" name="post[category][]" required="required"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>), + select("post", "category", %w(abe mus hest), {}, required: true, multiple: true) ) end - + def test_select_with_fixnum @post = Post.new @post.category = "" |