diff options
author | Kir Shatrov <shatrov@me.com> | 2017-06-29 20:25:54 +0300 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2017-06-30 17:29:13 +0300 |
commit | da895edf2e43d8c03089df7042a5bff7ef15fff0 (patch) | |
tree | dc0e043678882fb41299c9dd1427fa31fed9e9ab | |
parent | 5fe2a4f929fff7fa725545c47ac0f9372d8c643d (diff) | |
download | rails-da895edf2e43d8c03089df7042a5bff7ef15fff0.tar.gz rails-da895edf2e43d8c03089df7042a5bff7ef15fff0.tar.bz2 rails-da895edf2e43d8c03089df7042a5bff7ef15fff0.zip |
Fallback Parameters#to_s to Hash#to_s
Fixes https://github.com/rails/rails/issues/29617
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 9 | ||||
-rw-r--r-- | actionpack/test/controller/parameters/accessors_test.rb | 5 | ||||
-rw-r--r-- | actionview/test/template/form_tag_helper_test.rb | 6 |
3 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index cd6a0c0b98..3c16bde09c 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -180,6 +180,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? # # :call-seq: @@ -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' diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb index 7725c25e22..87407a4272 100644 --- a/actionpack/test/controller/parameters/accessors_test.rb +++ b/actionpack/test/controller/parameters/accessors_test.rb @@ -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" } diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 084c540139..c13d0c32ae 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -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="{"key"=>"value"}" />) + 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!" />) |