From dee00df11c34c43de65d36288f211a5229987ab2 Mon Sep 17 00:00:00 2001 From: claudiob Date: Mon, 29 Sep 2014 00:22:36 -0700 Subject: Fix how file_ and password_field_tag edit options This commit fixes the behavior of `file_field_tag` and `password_field_tag` when invoked with a hash of options. These two helpers are different from all the other ones in that they modify the options hash passed as a parameter, whereas all the other helpers duplicate it before updating it. The result is that *bad things* can happen if the user re-uses the same hash. For instance, users who write the following code to display a file field followed by a text field (both with the same class): ```rhtml <% options = {class: 'important'} %> <%= file_field_tag 'Upload', options %> <%= text_field_tag 'Name', options %> ``` would instead see **two file fields!** ```html ``` This PR replaces `update` with `merge` in the code of the two helpers, fixing the issue above. The included test verifies the change, since it passes after this PR, but fails before with the following error: ``` Expected: Actual: ``` --- actionview/test/template/form_tag_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 771e3fefc3..2d89332841 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -170,6 +170,13 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_multiple_field_tags_with_same_options + options = {class: 'important'} + assert_dom_equal %(), file_field_tag("title", options) + assert_dom_equal %(), password_field_tag("title", "Hello!", options) + assert_dom_equal %(), text_field_tag("title", "Hello!", options) + end + def test_radio_button_tag actual = radio_button_tag "people", "david" expected = %() -- cgit v1.2.3