Merge pull request #44749 from SkipKayhil/fix-params-to-yaml

fix serializing Parameters as yaml
This commit is contained in:
Aaron Patterson 2022-03-23 08:46:37 -07:00 committed by GitHub
commit d02cdf2ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -908,6 +908,10 @@ module ActionController
end
end
def encode_with(coder) # :nodoc:
coder.map = { "parameters" => @parameters, "permitted" => @permitted }
end
# Returns duplicate of object including all parameters.
def deep_dup
self.class.new(@parameters.deep_dup, @logging_context).tap do |duplicate|

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
require "abstract_unit"
class IntegrationController < ActionController::Base
def yaml_params
render plain: params.to_yaml
end
end
class ActionControllerParametersIntegrationTest < ActionController::TestCase
tests IntegrationController
test "parameters can be serialized as yaml" do
post :yaml_params, params: { person: { name: "Mjallo!" } }
expected = <<~YAML
--- !ruby/object:ActionController::Parameters
parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
person: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: Mjallo!
controller: integration
action: yaml_params
permitted: false
YAML
assert_equal expected, response.body
end
end