From e8e8617c390776e6d7b21ca79b99503a8afb19ae Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 11 Aug 2012 14:04:21 -0300 Subject: Simplify html attributes generation for options_for_select Further simplify the option_html_attributes method after the changes introduced in dacbcbe55745aa9e5484b10b11f65ccca7db1c54 to not escape the html options here (since they're going to be escaped down the chain in content tag). --- actionpack/lib/action_view/helpers/form_options_helper.rb | 8 +++++--- actionpack/test/template/form_options_helper_test.rb | 11 ++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) 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 -- cgit v1.2.3