1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fallback Parameters#to_s to Hash#to_s

Fixes https://github.com/rails/rails/issues/29617
This commit is contained in:
Kir Shatrov 2017-06-29 20:25:54 +03:00
parent 5fe2a4f929
commit da895edf2e
3 changed files with 19 additions and 1 deletions

View file

@ -179,6 +179,13 @@ module ActionController
#
# Returns a new array of the keys of the parameters.
##
# :method: to_s
#
# :call-seq:
# to_s()
# Returns the content of the parameters as a string.
##
# :method: value?
#
@ -195,7 +202,7 @@ module ActionController
#
# Returns a new array of the values of the parameters.
delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
:as_json, to: :@parameters
:as_json, :to_s, to: :@parameters
# By default, never raise an UnpermittedParameters exception if these
# params are present. The default includes both 'controller' and 'action'

View file

@ -35,6 +35,11 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
assert @params.as_json.key? "person"
end
test "to_s returns the string representation of the parameters hash" do
assert_equal '{"person"=>{"age"=>"32", "name"=>{"first"=>"David", "last"=>"Heinemeier Hansson"}, ' \
'"addresses"=>[{"city"=>"Chicago", "state"=>"Illinois"}]}}', @params.to_s
end
test "each carries permitted status" do
@params.permit!
@params.each { |key, value| assert(value.permitted?) if key == "person" }

View file

@ -345,6 +345,12 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
def test_text_field_tag_with_ac_parameters
actual = text_field_tag "title", ActionController::Parameters.new(key: "value")
expected = %(<input id="title" name="title" type="text" value="{&quot;key&quot;=&gt;&quot;value&quot;}" />)
assert_dom_equal expected, actual
end
def test_text_field_tag_size_string
actual = text_field_tag "title", "Hello!", "size" => "75"
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)