mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
checking for nested attributes when attribute names specified to wrap them as well
This commit is contained in:
parent
7b51b140d5
commit
dd423a743e
2 changed files with 22 additions and 7 deletions
|
@ -112,14 +112,15 @@ module ActionController
|
||||||
else
|
else
|
||||||
self.include = m.attribute_names
|
self.include = m.attribute_names
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if m.respond_to?(:nested_attributes_options) && m.nested_attributes_options.any?
|
|
||||||
nested_attributes_names = self.nested_attributes_options.keys.map do |key|
|
|
||||||
key.to_s.concat('_attributes').to_sym
|
|
||||||
end
|
|
||||||
self.include += nested_attributes_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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -255,6 +255,20 @@ class ParamsWrapperTest < ActionController::TestCase
|
||||||
assert_equal "", @response.body
|
assert_equal "", @response.body
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
class NamespacedParamsWrapperTest < ActionController::TestCase
|
class NamespacedParamsWrapperTest < ActionController::TestCase
|
||||||
|
|
Loading…
Reference in a new issue