Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap stored accessors in parameters #28056

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion actionpack/lib/action_controller/metal/params_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ 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
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/controller/params_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def self.attribute_names
end

class Person
def self.stores_attributes
{ settings: [:color, :size] }
end

def self.attribute_names
[]
end
Expand Down Expand Up @@ -62,6 +66,15 @@ def test_derived_name_from_controller
end
end

def test_store_accessors_wrapped
with_default_wrapper_options do
@request.env["CONTENT_TYPE"] = "application/json"
post :parse, params: { "username" => "sikachu", "color" => "blue", "size" => "large" }
assert_parameters("username" => "sikachu", "color" => "blue", "size" => "large",
"user" => { "username" => "sikachu", "color" => "blue", "size" => "large" })
end
end

def test_specify_wrapper_name
with_default_wrapper_options do
UsersController.wrap_parameters :person
Expand Down