Skip to content
Browse files

Simplify html attributes generation for options_for_select

Further simplify the option_html_attributes method after the changes
introduced in dacbcbe to not escape the
html options here (since they're going to be escaped down the chain in
content tag).
  • Loading branch information...
1 parent ce06b8a commit e8e8617c390776e6d7b21ca79b99503a8afb19ae @carlosantoniodasilva carlosantoniodasilva committed Aug 11, 2012
View
8 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -708,9 +708,11 @@ def collection_check_boxes(object, method, collection, value_method, text_method
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
11 actionpack/test/template/form_options_helper_test.rb
@@ -1164,11 +1164,12 @@ def test_options_for_select_with_special_characters
)
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

0 comments on commit e8e8617

Please sign in to comment.
Something went wrong with that request. Please try again.