未验证 提交 62b7ad46 编写于 作者: R Rafael Mendonça França

Merge pull request #30965 from kmanzana/master

Wrap accepted nested attributes params
......@@ -112,6 +112,14 @@ def include
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
......
......@@ -255,6 +255,20 @@ def test_handles_empty_content_type
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册