aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafael.franca@plataformatec.com.br>2012-05-13 00:47:34 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-13 01:00:31 -0300
commit521e964411114a9ff8c95f4129ca7ade8f972d53 (patch)
treef748930bc4ec797ba706f6d122c7c9e9f9a8be00 /actionpack
parent30818561158dce27f3b0ae3f659a7bfdc867b834 (diff)
downloadrails-521e964411114a9ff8c95f4129ca7ade8f972d53.tar.gz
rails-521e964411114a9ff8c95f4129ca7ade8f972d53.tar.bz2
rails-521e964411114a9ff8c95f4129ca7ade8f972d53.zip
Do not add `:include_blank` option if prompt is present
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/tags/base.rb6
-rw-r--r--actionpack/test/template/form_options_helper_test.rb7
2 files changed, 10 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb
index 607954e762..380ebe4b65 100644
--- a/actionpack/lib/action_view/helpers/tags/base.rb
+++ b/actionpack/lib/action_view/helpers/tags/base.rb
@@ -121,7 +121,7 @@ module ActionView
def select_content_tag(option_tags, options, html_options)
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
- options[:include_blank] ||= true if option_required?(html_options)
+ options[:include_blank] ||= true unless options[:prompt] || select_not_required?(html_options)
select = content_tag("select", add_options(option_tags, options, value(object)), html_options)
if html_options["multiple"] && options.fetch(:include_hidden, true)
@@ -131,8 +131,8 @@ module ActionView
end
end
- def option_required?(html_options)
- html_options["required"] && !html_options["multiple"] && !(html_options["size"].to_i > 1)
+ def select_not_required?(html_options)
+ !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 fee63b76c7..2cff91adda 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -648,6 +648,13 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
+ def test_required_select_with_prompt
+ assert_dom_equal(
+ %(<select id="post_category" name="post[category]" required="required"><option value="">Select one</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), { prompt: "Select one" }, required: true)
+ )
+ 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>),