Skip to content

Commit

Permalink
Ensure option for select helper responds to #first before comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Rose committed Dec 20, 2011
1 parent cf2d31a commit bd89946
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_options_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?(:first) && 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])
Expand Down
18 changes: 18 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit bd89946

Please sign in to comment.