diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-20 13:48:34 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-20 13:48:34 -0800 |
commit | a2f5df526c74a4c89e5226f5c5bd23f149b36b5d (patch) | |
tree | 87583ad9d55b28e81f6c67baf0c018002302b665 | |
parent | cf2d31ab0b07e1c5b124209c85993df303c961f1 (diff) | |
parent | a1b2dbd7d4e95fdde64a6b0529f6233efcdc99fe (diff) | |
download | rails-a2f5df526c74a4c89e5226f5c5bd23f149b36b5d.tar.gz rails-a2f5df526c74a4c89e5226f5c5bd23f149b36b5d.tar.bz2 rails-a2f5df526c74a4c89e5226f5c5bd23f149b36b5d.zip |
Merge pull request #4080 from heimidal/3-2-stable
Fix regression in select form helper when options are non-string values
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index f895cad058..3ee0d8ebc5 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -584,7 +584,7 @@ module ActionView # [nil, []] # { nil => [] } # - if !choices.empty? && Array === choices.first.last + if !choices.empty? && choices.first.respond_to?(:last) && Array === choices.first.last option_tags = grouped_options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) else option_tags = options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 469718e1bd..4a889beadd 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -596,6 +596,24 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_nil + @post = Post.new + @post.category = "othervalue" + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"othervalue\" selected=\"selected\">othervalue</option></select>", + select("post", "category", [nil, "othervalue"]) + ) + end + + def test_select_with_fixnum + @post = Post.new + @post.category = "" + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"1\">1</option></select>", + select("post", "category", [1], :prompt => true, :include_blank => true) + ) + end + def test_list_of_lists @post = Post.new @post.category = "" |