提交 d77b306b 编写于 作者: P Prem Sichanugrist

Make ParamsWrapper calling newly introduced `Model.attribute_names` instead of `.column_names`

上级 5ca67eca
...@@ -163,8 +163,8 @@ def _set_wrapper_defaults(options, model=nil) ...@@ -163,8 +163,8 @@ def _set_wrapper_defaults(options, model=nil)
unless options[:only] || options[:except] unless options[:only] || options[:except]
model ||= _default_wrap_model model ||= _default_wrap_model
if !(model.respond_to?(:abstract_class?) && model.abstract_class?) && model.respond_to?(:column_names) if model.respond_to?(:attribute_names) && model.attribute_names.present?
options[:only] = model.column_names options[:only] = model.attribute_names
end end
end end
......
...@@ -133,9 +133,8 @@ def test_nested_params ...@@ -133,9 +133,8 @@ def test_nested_params
end end
def test_derived_wrapped_keys_from_matching_model def test_derived_wrapped_keys_from_matching_model
User.expects(:respond_to?).with(:abstract_class?).returns(false) User.expects(:respond_to?).with(:attribute_names).returns(true)
User.expects(:respond_to?).with(:column_names).returns(true) User.expects(:attribute_names).twice.returns(["username"])
User.expects(:column_names).returns(["username"])
with_default_wrapper_options do with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json' @request.env['CONTENT_TYPE'] = 'application/json'
...@@ -146,9 +145,8 @@ def test_derived_wrapped_keys_from_matching_model ...@@ -146,9 +145,8 @@ def test_derived_wrapped_keys_from_matching_model
def test_derived_wrapped_keys_from_specified_model def test_derived_wrapped_keys_from_specified_model
with_default_wrapper_options do with_default_wrapper_options do
Person.expects(:respond_to?).with(:abstract_class?).returns(false) Person.expects(:respond_to?).with(:attribute_names).returns(true)
Person.expects(:respond_to?).with(:column_names).returns(true) Person.expects(:attribute_names).twice.returns(["username"])
Person.expects(:column_names).returns(["username"])
UsersController.wrap_parameters Person UsersController.wrap_parameters Person
...@@ -159,8 +157,8 @@ def test_derived_wrapped_keys_from_specified_model ...@@ -159,8 +157,8 @@ def test_derived_wrapped_keys_from_specified_model
end end
def test_not_wrapping_abstract_model def test_not_wrapping_abstract_model
User.expects(:respond_to?).with(:abstract_class?).returns(true) User.expects(:respond_to?).with(:attribute_names).returns(true)
User.expects(:abstract_class?).returns(true) User.expects(:attribute_names).returns([])
with_default_wrapper_options do with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json' @request.env['CONTENT_TYPE'] = 'application/json'
...@@ -198,13 +196,13 @@ def parse ...@@ -198,13 +196,13 @@ def parse
end end
class SampleOne class SampleOne
def self.column_names def self.attribute_names
["username"] ["username"]
end end
end end
class SampleTwo class SampleTwo
def self.column_names def self.attribute_names
["title"] ["title"]
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册