forked from yasslab/railsguides.jp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #25735 from timrogers/actioncontroller-parameters-dup
Stop changes to a dupped `ActionController::Parameters` mutating the original
- Loading branch information
Showing
2 changed files
with
48 additions
and
14 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
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,43 @@ | ||
require 'abstract_unit' | ||
require 'action_controller/metal/strong_parameters' | ||
|
||
class ParametersDupTest < ActiveSupport::TestCase | ||
setup do | ||
ActionController::Parameters.permit_all_parameters = false | ||
|
||
@params = ActionController::Parameters.new( | ||
person: { | ||
age: '32', | ||
name: { | ||
first: 'David', | ||
last: 'Heinemeier Hansson' | ||
}, | ||
addresses: [{city: 'Chicago', state: 'Illinois'}] | ||
} | ||
) | ||
end | ||
|
||
test "a duplicate maintains the original's permitted status" do | ||
@params.permit! | ||
dupped_params = @params.dup | ||
assert dupped_params.permitted? | ||
end | ||
|
||
test "a duplicate maintains the original's parameters" do | ||
@params.permit! | ||
dupped_params = @params.dup | ||
assert_equal @params.to_h, dupped_params.to_h | ||
end | ||
|
||
test "changes to a duplicate's parameters do not affect the original" do | ||
dupped_params = @params.dup | ||
dupped_params.delete(:person) | ||
assert_not_equal @params, dupped_params | ||
end | ||
|
||
test "changes tp a duplicate's permitted status do not affect the original" do | ||
dupped_params = @params.dup | ||
dupped_params.permit! | ||
assert_not_equal @params, dupped_params | ||
end | ||
end |