Skip to content

Commit

Permalink
fix serializing Parameters as yaml
Browse files Browse the repository at this point in the history
This has been broken since the logging context was added in
6be9c49

Also added a higher level test to ensure that this isn't broken again in
the future.
  • Loading branch information
skipkayhil committed Mar 23, 2022
1 parent 61d6eb1 commit 535113e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,10 @@ def init_with(coder) # :nodoc:
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|
Expand Down
27 changes: 27 additions & 0 deletions actionpack/test/controller/parameters_integration_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 535113e

Please sign in to comment.