Skip to content

Commit

Permalink
Deprecated should_require_unique_attributes in favor of should_valida…
Browse files Browse the repository at this point in the history
…te_uniqueness_of
  • Loading branch information
jferris committed Jan 30, 2009
1 parent 205b897 commit 192d744
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions lib/shoulda/active_record/macros.rb
Expand Up @@ -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."
Expand All @@ -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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/address_test.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit/post_test.rb
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit/user_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 192d744

Please sign in to comment.