aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/parameters/serialization_test.rb
blob: 84193e304aa64af20528e6d917a6cc36cc311826 (plain) (blame)
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
require 'abstract_unit'
require 'action_controller/metal/strong_parameters'
require 'active_support/core_ext/string/strip'

class ParametersSerializationTest < ActiveSupport::TestCase
  test 'yaml serialization' do
    assert_equal <<-end_of_yaml.strip_heredoc, YAML.dump(ActionController::Parameters.new(key: :value))
      --- !ruby/object:ActionController::Parameters
      parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
        key: :value
      permitted: false
    end_of_yaml
  end

  test 'yaml deserialization' do
    params = ActionController::Parameters.new(key: :value)
    roundtripped = YAML.load(YAML.dump(params))

    assert_equal params, roundtripped
    assert_not roundtripped.permitted?
  end

  test 'yaml backwardscompatible with psych 2.0.8 format' do
    params = YAML.load <<-end_of_yaml.strip_heredoc
      --- !ruby/hash:ActionController::Parameters
      key: :value
    end_of_yaml

    assert_equal :value, params[:key]
    assert_not params.permitted?
  end

  test 'yaml backwardscompatible with psych 2.0.9+ format' do
    params = YAML.load(<<-end_of_yaml.strip_heredoc)
      --- !ruby/hash-with-ivars:ActionController::Parameters
      elements:
        key: :value
      ivars:
        :@permitted: false
    end_of_yaml

    assert_equal :value, params[:key]
    assert_not params.permitted?
  end
end