diff options
author | Matt Casper <matthewvcasper@gmail.com> | 2017-03-29 09:56:27 -0500 |
---|---|---|
committer | Michael Stock <mikeastock@gmail.com> | 2017-03-29 15:55:09 -0500 |
commit | 0117810cdab34d168b0579a6736c5d58c5ab84c7 (patch) | |
tree | 4021e5a1e5181aa63e189297ac5a97ef135e9580 /actionpack/test/controller/parameters | |
parent | 55ccec637212a2232a64f86360b2a25fa1c25759 (diff) | |
download | rails-0117810cdab34d168b0579a6736c5d58c5ab84c7.tar.gz rails-0117810cdab34d168b0579a6736c5d58c5ab84c7.tar.bz2 rails-0117810cdab34d168b0579a6736c5d58c5ab84c7.zip |
Add aliases for reverse_merge to with_defaults
In the context of controller parameters, reverse_merge is commonly used
to provide defaults for user input. Having an alias to reverse_merge
called with_defaults feels more idiomatic for Rails.
Diffstat (limited to 'actionpack/test/controller/parameters')
-rw-r--r-- | actionpack/test/controller/parameters/parameters_permit_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 9f3025587e..3e067314d6 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -310,6 +310,14 @@ class ParametersPermitTest < ActiveSupport::TestCase refute_predicate merged_params[:person], :empty? end + test "#with_defaults is an alias of reverse_merge" do + default_params = ActionController::Parameters.new(id: "1234", person: {}).permit! + merged_params = @params.with_defaults(default_params) + + assert_equal "1234", merged_params[:id] + refute_predicate merged_params[:person], :empty? + end + test "not permitted is sticky beyond reverse_merge" do refute_predicate @params.reverse_merge(a: "b"), :permitted? end @@ -327,6 +335,14 @@ class ParametersPermitTest < ActiveSupport::TestCase refute_predicate @params[:person], :empty? end + test "#with_defaults! is an alias of reverse_merge!" do + default_params = ActionController::Parameters.new(id: "1234", person: {}).permit! + @params.with_defaults!(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" } |