Permalink
Browse files

Deprecated should_protect_attributes in favor of should_not_allow_mas…

…s_assignment_of
  • Loading branch information...
1 parent f12d1ab commit f937c08144229a8f677aa26d3623e38622a30cb4 @jferris jferris committed Jan 30, 2009
Showing with 14 additions and 7 deletions.
  1. +10 −3 lib/shoulda/active_record/macros.rb
  2. +1 −1 test/fail_macros.rb
  3. +1 −1 test/unit/tag_test.rb
  4. +2 −2 test/unit/user_test.rb
@@ -9,7 +9,7 @@ module ActiveRecord # :nodoc:
# should_not_allow_values_for :phone_number, "abcd", "1234"
# should_allow_values_for :phone_number, "(123) 456-7890"
#
- # should_protect_attributes :password
+ # should_not_allow_mass_assignment_of :password
#
# should_have_one :profile
# should_have_many :dogs
@@ -107,9 +107,9 @@ def should_require_unique_attributes(*attributes)
# Ensures that the attribute cannot be set on mass update.
#
- # should_protect_attributes :password, :admin_flag
+ # should_not_allow_mass_assignment_of :password, :admin_flag
#
- def should_protect_attributes(*attributes)
+ def should_not_allow_mass_assignment_of(*attributes)
get_options!(attributes)
klass = model_class
@@ -121,6 +121,13 @@ def should_protect_attributes(*attributes)
end
end
+ # Deprecated. See should_not_allow_mass_assignment_of
+ def should_protect_attributes(*attributes)
+ warn "[DEPRECATION] should_protect_attributes is deprecated. " <<
+ "Use should_not_allow_mass_assignment_of instead."
+ should_not_allow_mass_assignment_of(*attributes)
+ end
+
# Ensures that the attribute cannot be changed once the record has been created.
#
# should_have_readonly_attributes :password, :admin_flag
View
@@ -9,7 +9,7 @@ module ClassMethods
#
# should_fail do
# should_validate_presence_of :comments
- # should_protect_attributes :name
+ # should_not_allow_mass_assignment_of :name
# end
def should_fail(&block)
context "should fail when trying to run:" do
View
@@ -9,6 +9,6 @@ class TagTest < Test::Unit::TestCase
should_protect_attributes :secret
should_fail do
- should_protect_attributes :name
+ should_not_allow_mass_assignment_of :name
end
end
View
@@ -39,7 +39,7 @@ class UserTest < Test::Unit::TestCase
should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
should_ensure_length_in_range :email, 1..100
should_ensure_value_in_range :age, 1..100
- should_protect_attributes :password
+ should_not_allow_mass_assignment_of :password
should_have_class_methods :find, :destroy
should_have_instance_methods :email, :age, :email=, :valid?
should_have_db_columns :name, :email, :age
@@ -56,6 +56,6 @@ class UserTest < Test::Unit::TestCase
should_have_readonly_attributes :name
should_fail do
- should_protect_attributes :name, :age
+ should_not_allow_mass_assignment_of :name, :age
end
end

4 comments on commit f937c08

Isn’t this going backwards form the recent deprecations. All the others have been moving to look more like what would be typed in the model, but this one is moving away form that. What is the reason?

Contributor

cristibalan replied Feb 5, 2009

My random opinion is that should_attr_accesible and should_attr_protected sound kinda crappy.

Also, it seems that you have to list all your columns because there’s no difference in how attr_accessible and attr_protected are tested. I’d like these a bit more:
- should_white_list_mass_assignement_to :blah
- should_black_list_mass_assignement_to :blah

I wasn’t thinking should_attr_accesible. I was really thinking that the old name was better.

Collaborator

rmm5t replied Feb 7, 2009

The new name conveys what is actually happening. The old name of should_protect_attributes never conveyed this, and for that matter, neither does attr_protected or attr_accessible.

This was also done to more easily name the new should_allow_mass_assignment_of macro that was committed here

For more info, see Ticket #106 in LH.

Please sign in to comment.