Permalink
Browse files

Deprecated should_require_unique_attributes in favor of should_valida…

…te_uniqueness_of
  • Loading branch information...
1 parent 205b897 commit 192d7443b0a22889e02dca0b18c002c64568097f @jferris jferris committed Jan 30, 2009
Showing with 17 additions and 9 deletions.
  1. +14 −6 lib/shoulda/active_record/macros.rb
  2. +1 −1 test/unit/address_test.rb
  3. +1 −1 test/unit/post_test.rb
  4. +1 −1 test/unit/user_test.rb
@@ -56,6 +56,7 @@ def should_validate_presence_of(*attributes)
end
end
+ # Deprecated. See should_validate_presence_of
def should_require_attributes(*attributes)
warn "[DEPRECATION] should_require_attributes is deprecated. " <<
"Use should_validate_presence_of instead."
@@ -74,13 +75,13 @@ def should_require_attributes(*attributes)
# exact match. Ignored by non-text attributes. Default = <tt>true</tt>
#
# Examples:
- # should_require_unique_attributes :keyword, :username
- # should_require_unique_attributes :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
- # should_require_unique_attributes :email, :scoped_to => :name
- # should_require_unique_attributes :address, :scoped_to => [:first_name, :last_name]
- # should_require_unique_attributes :email, :case_sensitive => false
+ # should_validate_uniqueness_of :keyword, :username
+ # should_validate_uniqueness_of :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
+ # should_validate_uniqueness_of :email, :scoped_to => :name
+ # should_validate_uniqueness_of :address, :scoped_to => [:first_name, :last_name]
+ # should_validate_uniqueness_of :email, :case_sensitive => false
#
- def should_require_unique_attributes(*attributes)
+ def should_validate_uniqueness_of(*attributes)
message, scope, case_sensitive = get_options!(attributes, :message, :scoped_to, :case_sensitive)
scope = [*scope].compact
case_sensitive = true if case_sensitive.nil?
@@ -97,6 +98,13 @@ def should_require_unique_attributes(*attributes)
end
end
+ # Deprecated. See should_validate_uniqueness_of
+ def should_require_unique_attributes(*attributes)
+ warn "[DEPRECATION] should_require_unique_attributes is deprecated. " <<
+ "Use should_validate_uniqueness_of instead."
+ should_validate_uniqueness_of(*attributes)
+ end
+
# Ensures that the attribute cannot be set on mass update.
#
# should_protect_attributes :password, :admin_flag
@@ -4,7 +4,7 @@ class AddressTest < Test::Unit::TestCase
fixtures :all
should_belong_to :addressable
- should_require_unique_attributes :title, :scoped_to => [:addressable_id, :addressable_type]
+ should_validate_uniqueness_of :title, :scoped_to => [:addressable_id, :addressable_type]
should_ensure_length_at_least :zip, 5
should_only_allow_numeric_values_for :zip
end
View
@@ -14,6 +14,6 @@ class PostTest < Test::Unit::TestCase
should_only_allow_numeric_values_for :user_id
should_fail do
- should_require_unique_attributes :title, :case_sensitive => false
+ should_validate_uniqueness_of :title, :case_sensitive => false
end
end
View
@@ -47,7 +47,7 @@ class UserTest < Test::Unit::TestCase
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
:null => true, :scale => nil
should_require_acceptance_of :eula
- should_require_unique_attributes :email, :scoped_to => :name, :case_sensitive => false
+ should_validate_uniqueness_of :email, :scoped_to => :name, :case_sensitive => false
should_ensure_length_is :ssn, 9, :message => "Social Security Number is not the right length"
should_only_allow_numeric_values_for :ssn

0 comments on commit 192d744

Please sign in to comment.