aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-08-11 14:04:21 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-08-11 14:04:22 -0300
commite8e8617c390776e6d7b21ca79b99503a8afb19ae (patch)
treeb4ab786784a97efb6d8ba7a48f233f444cb2f75c
parentce06b8a56c5647b9b963c2331e3912fbc54e950c (diff)
downloadrails-e8e8617c390776e6d7b21ca79b99503a8afb19ae.tar.gz
rails-e8e8617c390776e6d7b21ca79b99503a8afb19ae.tar.bz2
rails-e8e8617c390776e6d7b21ca79b99503a8afb19ae.zip
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).
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb8
-rw-r--r--actionpack/test/template/form_options_helper_test.rb11
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