1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplify html attributes generation for options_for_select

Further simplify the option_html_attributes method after the changes
introduced in dacbcbe557 to not escape the
html options here (since they're going to be escaped down the chain in
content tag).
This commit is contained in:
Carlos Antonio da Silva 2012-08-11 14:04:21 -03:00
parent ce06b8a56c
commit e8e8617c39
2 changed files with 11 additions and 8 deletions

View file

@ -708,9 +708,11 @@ module ActionView
private
def option_html_attributes(element)
return {} unless Array === element
Hash[element.select { |e| Hash === e }.reduce({}, :merge).map { |k, v| [k, v] }]
if Array === element
element.select { |e| Hash === e }.reduce({}, :merge)
else
{}
end
end
def option_text_and_value(option)

View file

@ -1164,11 +1164,12 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
def test_option_html_attributes_from_without_hash
assert_equal(
{},
option_html_attributes([ 'foo', 'bar' ])
)
def test_option_html_attributes_with_no_array_element
assert_equal({}, option_html_attributes('foo'))
end
def test_option_html_attributes_without_hash
assert_equal({}, option_html_attributes([ 'foo', 'bar' ]))
end
def test_option_html_attributes_with_single_element_hash