aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-03-21 16:52:47 -0400
committerGitHub <noreply@github.com>2017-03-21 16:52:47 -0400
commit88b16843f67bcd96395444ba8f139895351da0bc (patch)
tree23c04e185936996f1e3d10cf5d71cb4f1022ecfe
parentb7bd4e2848145fe6b342d510b9e250ab7799563c (diff)
parentea5aa2525b4fbc7d8323a7e4c3ee98db2ee5acb4 (diff)
downloadrails-88b16843f67bcd96395444ba8f139895351da0bc.tar.gz
rails-88b16843f67bcd96395444ba8f139895351da0bc.tar.bz2
rails-88b16843f67bcd96395444ba8f139895351da0bc.zip
Merge pull request #28056 from sngeth/wrap_store_accessors_in_params
Wrap stored accessors in parameters
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb6
-rw-r--r--actionpack/test/controller/params_wrapper_test.rb13
2 files changed, 18 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index 3cca5e8906..a89fc1678b 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -105,7 +105,11 @@ module ActionController
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
diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb
index faa57c4559..1eb92abae4 100644
--- a/actionpack/test/controller/params_wrapper_test.rb
+++ b/actionpack/test/controller/params_wrapper_test.rb
@@ -35,6 +35,10 @@ class ParamsWrapperTest < ActionController::TestCase
end
class Person
+ def self.stores_attributes
+ { settings: [:color, :size] }
+ end
+
def self.attribute_names
[]
end
@@ -62,6 +66,15 @@ class ParamsWrapperTest < ActionController::TestCase
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