diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-30 12:44:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-30 12:44:31 -0400 |
commit | de011ac624a0e15ad064c0e99562f4c2aba07286 (patch) | |
tree | ce23fad0c8c347e9264eaab537f89ae909493896 | |
parent | 6671340d586d419107952a756039db0c258d095f (diff) | |
parent | da895edf2e43d8c03089df7042a5bff7ef15fff0 (diff) | |
download | rails-de011ac624a0e15ad064c0e99562f4c2aba07286.tar.gz rails-de011ac624a0e15ad064c0e99562f4c2aba07286.tar.bz2 rails-de011ac624a0e15ad064c0e99562f4c2aba07286.zip |
Merge pull request #29630 from kirs/fallback-tos_parameters
Fallback Parameters#to_s to Hash#to_s
-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!" />) |