diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index f3237f82d5..775993fe03 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -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) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index d234e6633c..e1ce5c5568 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -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