Adds support to wrap aliased attributed in object hash in params wrapper.
Fixes #24213 Closes #24338
This commit is contained in:
parent
eff64790fc
commit
5b67382122
@ -107,10 +107,14 @@ def include
|
||||
|
||||
unless super || exclude
|
||||
if m.respond_to?(:attribute_names) && m.attribute_names.any?
|
||||
self.include = m.attribute_names
|
||||
|
||||
if m.respond_to?(:stored_attributes) && !m.stored_attributes.empty?
|
||||
self.include = m.attribute_names + m.stored_attributes.values.flatten.map(&:to_s)
|
||||
else
|
||||
self.include = m.attribute_names
|
||||
self.include += m.stored_attributes.values.flatten.map(&:to_s)
|
||||
end
|
||||
|
||||
if m.respond_to?(:attribute_aliases) && m.attribute_aliases.any?
|
||||
self.include += m.attribute_aliases.keys
|
||||
end
|
||||
|
||||
if m.respond_to?(:nested_attributes_options) && m.nested_attributes_options.keys.any?
|
||||
|
@ -293,6 +293,10 @@ class SampleOne
|
||||
def self.attribute_names
|
||||
["username"]
|
||||
end
|
||||
|
||||
def self.attribute_aliases
|
||||
{ "nick" => "username" }
|
||||
end
|
||||
end
|
||||
|
||||
class SampleTwo
|
||||
@ -328,6 +332,19 @@ def test_namespace_lookup_from_model
|
||||
end
|
||||
end
|
||||
|
||||
def test_namespace_lookup_from_model_alias
|
||||
Admin.const_set(:User, Class.new(SampleOne))
|
||||
begin
|
||||
with_default_wrapper_options do
|
||||
@request.env["CONTENT_TYPE"] = "application/json"
|
||||
post :parse, params: { "nick" => "sikachu", "title" => "Developer" }
|
||||
assert_parameters({ "nick" => "sikachu", "title" => "Developer", "user" => { "nick" => "sikachu" } })
|
||||
end
|
||||
ensure
|
||||
Admin.send :remove_const, :User
|
||||
end
|
||||
end
|
||||
|
||||
def test_hierarchy_namespace_lookup_from_model
|
||||
Object.const_set(:User, Class.new(SampleTwo))
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user