1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# frozen_string_literal: true
require "abstract_unit"
class IntegrationController < ActionController::Base
def yaml_params
render plain: params.to_yaml
end
def permit_params
params.permit(
key1: {}
)
render plain: "Home"
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
# Ensure no deprecation warning from comparing AC::Parameters against Hash
# See https://github.com/rails/rails/issues/44940
test "identical arrays can be permitted" do
params = {
key1: {
a: [{ same_key: { c: 1 } }],
b: [{ same_key: { c: 1 } }]
}
}
assert_not_deprecated(ActionController.deprecator) do
post :permit_params, params: params
end
assert_response :ok
end
end
|