Permalink
Browse files

Merge pull request #4080 from heimidal/3-2-stable

Fix regression in select form helper when options are non-string values
  • Loading branch information...
josevalim committed Dec 20, 2011
2 parents cf2d31a + a1b2dbd commit a2f5df526c74a4c89e5226f5c5bd23f149b36b5d
@@ -584,7 +584,7 @@ def to_select_tag(choices, options, html_options)
# [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])
@@ -596,6 +596,24 @@ def test_empty
)
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 = ""

0 comments on commit a2f5df5

Please sign in to comment.