From 94d84c5383fd2394577a286738e9d9663c6b8f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 13 May 2012 00:41:26 -0300 Subject: `:include_blank` should be true if the size option is nil --- actionpack/CHANGELOG.md | 2 +- actionpack/lib/action_view/helpers/tags/base.rb | 4 +-- .../test/template/form_options_helper_test.rb | 36 +++++++++++++--------- 3 files changed, 25 insertions(+), 17 deletions(-) (limited to 'actionpack') 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("post", "category", %w(abe mus hest), {}, required: true) + ) + end + end + + def test_required_select_display_size_equals_to_one assert_dom_equal( - "", - select("post", "category", %w( abe mus hest),{}, :required => true, :size => 1) + %(), + 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("post", "category", %w( abe mus hest),{}, :required => true, :size => 2) - ) + + def test_required_select_with_display_size_bigger_than_one + assert_dom_equal( + %(), + 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( - "", - select("post", "category", %w( abe mus hest), {}, :required => true, :size => 1, :multiple => true) + %(), + select("post", "category", %w(abe mus hest), {}, required: true, multiple: true) ) end - + def test_select_with_fixnum @post = Post.new @post.category = "" -- cgit v1.2.3