diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-10-25 13:16:44 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-10-25 13:16:44 -0400 |
commit | 62b7ad46c0f3ff24980956daadba46ccb2568445 (patch) | |
tree | 6caf2da47c1b5faacf92d1fecec839cefed480e4 | |
parent | 08df10a95b4a72128ff5e5cee858c29c149e22a7 (diff) | |
parent | dd423a743e9d47aaa3d15e4f7dc0fc64157cd55c (diff) | |
download | rails-62b7ad46c0f3ff24980956daadba46ccb2568445.tar.gz rails-62b7ad46c0f3ff24980956daadba46ccb2568445.tar.bz2 rails-62b7ad46c0f3ff24980956daadba46ccb2568445.zip |
Merge pull request #30965 from kmanzana/master
Wrap accepted nested attributes params
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/params_wrapper_test.rb | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index f4f2381286..a678377d4f 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -112,6 +112,14 @@ module ActionController else self.include = m.attribute_names end + + if m.respond_to?(:nested_attributes_options) && m.nested_attributes_options.keys.any? + self.include += m.nested_attributes_options.keys.map do |key| + key.to_s.concat("_attributes") + end + end + + self.include end end end diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index df68ef25a3..41b583d1a7 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -255,6 +255,20 @@ class ParamsWrapperTest < ActionController::TestCase assert_equal "", @response.body end end + + def test_derived_wrapped_keys_from_nested_attributes + def User.nested_attributes_options + { person: {} } + end + + assert_called(User, :attribute_names, times: 2, returns: ["username"]) do + with_default_wrapper_options do + @request.env["CONTENT_TYPE"] = "application/json" + post :parse, params: { "username" => "sikachu", "person_attributes" => { "title" => "Developer" } } + assert_parameters("username" => "sikachu", "person_attributes" => { "title" => "Developer" }, "user" => { "username" => "sikachu", "person_attributes" => { "title" => "Developer" } }) + end + end + end end class NamespacedParamsWrapperTest < ActionController::TestCase |