File: parameters_integration_test.rb

package info (click to toggle)
rails 2%3A7.2.2.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,352 kB
  • sloc: ruby: 349,799; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (51 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download
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