-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26017 from kaspth/parameters-yaml-format-backward…
…scompatibility Make Parameters support legacy YAML encodings.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
actionpack/test/controller/parameters/serialization_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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 hash inheriting parameters' do | ||
assert_equal ActionController::Parameters.new(key: :value), YAML.load(<<-end_of_yaml.strip_heredoc) | ||
--- !ruby/hash-with-ivars:ActionController::Parameters | ||
elements: | ||
key: :value | ||
ivars: | ||
:@permitted: false | ||
end_of_yaml | ||
end | ||
end |