Skip to content

Commit

Permalink
fix stringify_keys destructive behavior for most FormTagHelper functions
Browse files Browse the repository at this point in the history
add four new tests to verify that the other three methods that called stringify_keys! are fixed. verified that the tests break in master without the code patch. Closes #2355
  • Loading branch information
waynn committed Aug 4, 2011
1 parent 2b925e8 commit 54b8356
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions actionpack/lib/action_view/helpers/form_tag_helper.rb
Expand Up @@ -304,7 +304,7 @@ def password_field_tag(name = "password", value = nil, options = {})
# text_area_tag 'comment', nil, :class => 'comment_input'
# # => <textarea class="comment_input" id="comment" name="comment"></textarea>
def text_area_tag(name, content = nil, options = {})
options.stringify_keys!
options = options.stringify_keys

if size = options.delete("size")
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
Expand Down Expand Up @@ -407,7 +407,7 @@ def radio_button_tag(name, value, checked = false, options = {})
# data-confirm="Are you sure?" />
#
def submit_tag(value = "Save changes", options = {})
options.stringify_keys!
options = options.stringify_keys

if disable_with = options.delete("disable_with")
options["data-disable-with"] = disable_with
Expand Down Expand Up @@ -458,7 +458,7 @@ def submit_tag(value = "Save changes", options = {})
def button_tag(content_or_options = nil, options = nil, &block)
options = content_or_options if block_given? && content_or_options.is_a?(Hash)
options ||= {}
options.stringify_keys!
options = options.stringify_keys

if disable_with = options.delete("disable_with")
options["data-disable-with"] = disable_with
Expand Down Expand Up @@ -497,7 +497,7 @@ def button_tag(content_or_options = nil, options = nil, &block)
# image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button")
# # => <input class="agree_disagree_button" disabled="disabled" src="/images/agree.png" type="image" />
def image_submit_tag(source, options = {})
options.stringify_keys!
options = options.stringify_keys

if confirm = options.delete("confirm")
options["data-confirm"] = confirm
Expand Down
24 changes: 24 additions & 0 deletions actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -505,6 +505,30 @@ def test_field_set_tag_in_erb
expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
end

def test_text_area_tag_options_symbolize_keys_side_effects
options = { :option => "random_option" }
actual = text_area_tag "body", "hello world", options
assert_equal options, { :option => "random_option" }
end

def test_submit_tag_options_symbolize_keys_side_effects
options = { :option => "random_option" }
actual = submit_tag "submit value", options
assert_equal options, { :option => "random_option" }
end

def test_button_tag_options_symbolize_keys_side_effects
options = { :option => "random_option" }
actual = button_tag "button value", options
assert_equal options, { :option => "random_option" }
end

def test_image_submit_tag_options_symbolize_keys_side_effects
options = { :option => "random_option" }
actual = image_submit_tag "submit source", options
assert_equal options, { :option => "random_option" }
end

def protect_against_forgery?
false
Expand Down

0 comments on commit 54b8356

Please sign in to comment.