mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove integration between attr_accessible/protected and AC::Metal::ParamsWrapper
This commit is contained in:
parent
d695fdbd11
commit
8c4de0e67f
3 changed files with 2 additions and 48 deletions
|
@ -42,9 +42,7 @@ module ActionController
|
|||
# end
|
||||
#
|
||||
# On ActiveRecord models with no +:include+ or +:exclude+ option set,
|
||||
# if attr_accessible is set on that model, it will only wrap the accessible
|
||||
# parameters, else it will only wrap the parameters returned by the class
|
||||
# method attribute_names.
|
||||
# it will only wrap the parameters returned by the class method attribute_names.
|
||||
#
|
||||
# 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
|
||||
|
@ -165,10 +163,7 @@ module ActionController
|
|||
|
||||
unless options[:include] || options[:exclude]
|
||||
model ||= _default_wrap_model
|
||||
role = options.fetch(:as, :default)
|
||||
if model.respond_to?(:accessible_attributes) && model.accessible_attributes(role).present?
|
||||
options[:include] = model.accessible_attributes(role).to_a
|
||||
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
|
||||
if model.respond_to?(:attribute_names) && model.attribute_names.present?
|
||||
options[:include] = model.attribute_names
|
||||
end
|
||||
end
|
||||
|
|
|
@ -155,7 +155,6 @@ class ParamsWrapperTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def test_derived_wrapped_keys_from_matching_model
|
||||
User.expects(:respond_to?).with(:accessible_attributes).returns(false)
|
||||
User.expects(:respond_to?).with(:attribute_names).returns(true)
|
||||
User.expects(:attribute_names).twice.returns(["username"])
|
||||
|
||||
|
@ -168,7 +167,6 @@ class ParamsWrapperTest < ActionController::TestCase
|
|||
|
||||
def test_derived_wrapped_keys_from_specified_model
|
||||
with_default_wrapper_options do
|
||||
Person.expects(:respond_to?).with(:accessible_attributes).returns(false)
|
||||
Person.expects(:respond_to?).with(:attribute_names).returns(true)
|
||||
Person.expects(:attribute_names).twice.returns(["username"])
|
||||
|
||||
|
@ -179,46 +177,8 @@ class ParamsWrapperTest < ActionController::TestCase
|
|||
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
|
||||
end
|
||||
end
|
||||
|
||||
def test_accessible_wrapped_keys_from_matching_model
|
||||
User.expects(:respond_to?).with(:accessible_attributes).returns(true)
|
||||
User.expects(:accessible_attributes).with(:default).twice.returns(["username"])
|
||||
|
||||
with_default_wrapper_options do
|
||||
@request.env['CONTENT_TYPE'] = 'application/json'
|
||||
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
|
||||
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu' }})
|
||||
end
|
||||
end
|
||||
|
||||
def test_accessible_wrapped_keys_from_specified_model
|
||||
with_default_wrapper_options do
|
||||
Person.expects(:respond_to?).with(:accessible_attributes).returns(true)
|
||||
Person.expects(:accessible_attributes).with(:default).twice.returns(["username"])
|
||||
|
||||
UsersController.wrap_parameters Person
|
||||
|
||||
@request.env['CONTENT_TYPE'] = 'application/json'
|
||||
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
|
||||
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
|
||||
end
|
||||
end
|
||||
|
||||
def test_accessible_wrapped_keys_with_role_from_specified_model
|
||||
with_default_wrapper_options do
|
||||
Person.expects(:respond_to?).with(:accessible_attributes).returns(true)
|
||||
Person.expects(:accessible_attributes).with(:admin).twice.returns(["username"])
|
||||
|
||||
UsersController.wrap_parameters Person, :as => :admin
|
||||
|
||||
@request.env['CONTENT_TYPE'] = 'application/json'
|
||||
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
|
||||
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
|
||||
end
|
||||
end
|
||||
|
||||
def test_not_wrapping_abstract_model
|
||||
User.expects(:respond_to?).with(:accessible_attributes).returns(false)
|
||||
User.expects(:respond_to?).with(:attribute_names).returns(true)
|
||||
User.expects(:attribute_names).returns([])
|
||||
|
||||
|
|
1
actionpack/test/fixtures/company.rb
vendored
1
actionpack/test/fixtures/company.rb
vendored
|
@ -1,6 +1,5 @@
|
|||
class Company < ActiveRecord::Base
|
||||
has_one :mascot
|
||||
attr_protected :rating
|
||||
self.sequence_name = :companies_nonstd_seq
|
||||
|
||||
validates_presence_of :name
|
||||
|
|
Loading…
Reference in a new issue