mirror of https://github.com/rails/rails
Merge pull request #44749 from SkipKayhil/fix-params-to-yaml
fix serializing Parameters as yaml
This commit is contained in:
commit
d02cdf2ffd
|
@ -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|
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue