提交 e5a9d289 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #29119 from spohlenz/fix-select-with-enumerable

Fix select tag helper used with Enumerable choices
......@@ -33,7 +33,7 @@ def render
# [nil, []]
# { nil => [] }
def grouped_choices?
!@choices.empty? && @choices.first.respond_to?(:last) && Array === @choices.first.last
!@choices.blank? && @choices.first.respond_to?(:last) && Array === @choices.first.last
end
end
end
......
......@@ -6,6 +6,15 @@ def category
end
end
class CustomEnumerable
include Enumerable
def each
yield "one"
yield "two"
end
end
class FormOptionsHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormOptionsHelper
......@@ -904,6 +913,14 @@ def test_select_with_range
)
end
def test_select_with_enumerable
@post = Post.new
assert_dom_equal(
"<select id=\"post_category\" name=\"post[category]\"><option value=\"one\">one</option>\n<option value=\"two\">two</option></select>",
select("post", "category", CustomEnumerable.new)
)
end
def test_collection_select
@post = Post.new
@post.author_name = "Babe"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册