diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-10 18:09:09 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-10 18:10:11 -0500 |
commit | c76190ed76d030452eeee9934f22b2f8bb21405b (patch) | |
tree | 9e1962b2de90688a9a450cfa451bc190482710a3 /actionpack/test/controller/parameters/parameters_permit_test.rb | |
parent | c56c4e4121635ec1221d1a83dd53cedf92ffa283 (diff) | |
parent | 4d7986283653ff4fbd5a82dd273ed9795a0c6a65 (diff) | |
download | rails-c76190ed76d030452eeee9934f22b2f8bb21405b.tar.gz rails-c76190ed76d030452eeee9934f22b2f8bb21405b.tar.bz2 rails-c76190ed76d030452eeee9934f22b2f8bb21405b.zip |
Merge pull request #28355 from Edouard-chin/reversemerge-for-strongparameters
Added `reverse_merge`/`reverse_merge!` to AC::Parameters:
[Rafael Mendonça França + Mitsutaka Mimura]
Diffstat (limited to 'actionpack/test/controller/parameters/parameters_permit_test.rb')
-rw-r--r-- | actionpack/test/controller/parameters/parameters_permit_test.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 8920914af1..b51c55b1f1 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -302,6 +302,35 @@ class ParametersPermitTest < ActiveSupport::TestCase assert_equal "32", @params[:person][:age] end + test "#reverse_merge with parameters" do + default_params = ActionController::Parameters.new(id: "1234", person: {}).permit! + merged_params = @params.reverse_merge(default_params) + + assert_equal "1234", merged_params[:id] + refute_predicate merged_params[:person], :empty? + end + + test "not permitted is sticky beyond reverse_merge!" do + merged_params = @params.reverse_merge(a: "b") + + refute_predicate @params, :permitted? + end + + test "permitted is sticky beyond reverse_merge!" do + @params.permit! + merged_params = @params.reverse_merge(a: "b") + + assert_predicate @params, :permitted? + end + + test "#reverse_merge! with parameters" do + default_params = ActionController::Parameters.new(id: "1234", person: {}).permit! + @params.reverse_merge!(default_params) + + assert_equal "1234", @params[:id] + refute_predicate @params[:person], :empty? + end + test "modifying the parameters" do @params[:person][:hometown] = "Chicago" @params[:person][:family] = { brother: "Jonas" } |