mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix select tag helper used with Enumerable choices
Allows a custom object implementing Enumerable to be used as the choices parameter for a select tag, which previously wasn't possible due to the call to `empty?` on the choices (which isn't implemented on Enumerable).
This commit is contained in:
parent
0714251b2d
commit
efe62b71d5
2 changed files with 18 additions and 1 deletions
|
@ -33,7 +33,7 @@ module ActionView
|
|||
# [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 @@ class Map < Hash
|
|||
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 @@ class FormOptionsHelperTest < ActionView::TestCase
|
|||
)
|
||||
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"
|
||||
|
|
Loading…
Reference in a new issue