Permalink
Browse files

Use `attribute_method_names` to wrap parameters

We also want to slice out the names of aliased attributes when wrapping
up params.
  • Loading branch information...
1 parent 217e902 commit 0c4934b3c498767ce8e97f1b72bad472df160bf2 @vanstee committed May 9, 2013
View
@@ -35,4 +35,8 @@
*Bryan Ricker*
+* Add support for wrapping parameters matching aliased attribute names.
+
+ *Patrick Van Stee*
+
Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md) for previous changes.
@@ -44,7 +44,7 @@ module ActionController
#
# On ActiveRecord models with no +:include+ or +:exclude+ option set,
# it will only wrap the parameters returned by the class method
- # <tt>attribute_names</tt>.
+ # <tt>attribute_method_names</tt>.
#
# If you're going to pass the parameters to an +ActiveModel+ object (such as
# <tt>User.new(params[:user])</tt>), you might consider passing the model class to
@@ -106,8 +106,8 @@ def include
@include_set = true
unless super || exclude
- if m.respond_to?(:attribute_names) && m.attribute_names.any?
- self.include = m.attribute_names
+ if m.respond_to?(:attribute_method_names) && m.attribute_method_names.any?
+ self.include = m.attribute_method_names
end
end
end
@@ -155,8 +155,8 @@ def test_nested_params
end
def test_derived_wrapped_keys_from_matching_model
- User.expects(:respond_to?).with(:attribute_names).returns(true)
- User.expects(:attribute_names).twice.returns(["username"])
+ User.expects(:respond_to?).with(:attribute_method_names).returns(true)
+ User.expects(:attribute_method_names).twice.returns(["username"])
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
@@ -167,8 +167,8 @@ def test_derived_wrapped_keys_from_matching_model
def test_derived_wrapped_keys_from_specified_model
with_default_wrapper_options do
- Person.expects(:respond_to?).with(:attribute_names).returns(true)
- Person.expects(:attribute_names).twice.returns(["username"])
+ Person.expects(:respond_to?).with(:attribute_method_names).returns(true)
+ Person.expects(:attribute_method_names).twice.returns(["username"])
UsersController.wrap_parameters Person
@@ -179,8 +179,8 @@ def test_derived_wrapped_keys_from_specified_model
end
def test_not_wrapping_abstract_model
- User.expects(:respond_to?).with(:attribute_names).returns(true)
- User.expects(:attribute_names).returns([])
+ User.expects(:respond_to?).with(:attribute_method_names).returns(true)
+ User.expects(:attribute_method_names).returns([])
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
@@ -209,13 +209,13 @@ def parse
end
class SampleOne
- def self.attribute_names
+ def self.attribute_method_names
["username"]
end
end
class SampleTwo
- def self.attribute_names
+ def self.attribute_method_names
["title"]
end
end
@@ -298,7 +298,7 @@ class IrregularInflectionParamsWrapperTest < ActionController::TestCase
include ParamsWrapperTestHelp
class ParamswrappernewsItem
- def self.attribute_names
+ def self.attribute_method_names
['test_attr']
end
end
@@ -514,7 +514,7 @@ def index
app_file 'app/models/post.rb', <<-RUBY
class Post
- def self.attribute_names
+ def self.attribute_method_names
%w(title)
end
end

0 comments on commit 0c4934b

Please sign in to comment.