deprecate should_require_attributes with warning message. replace with should_validate_presence_of.
This commit is contained in:
parent
32b54bd8ac
commit
205b897089
|
@ -55,8 +55,8 @@ Quick macro tests for your ActiveRecord associations and validations:
|
|||
should_have_many :tags, :through => :taggings
|
||||
|
||||
should_require_unique_attributes :title
|
||||
should_require_attributes :body, :message => /wtf/
|
||||
should_require_attributes :title
|
||||
should_validate_presence_of :body, :message => /wtf/
|
||||
should_validate_presence_of :title
|
||||
should_only_allow_numeric_values_for :user_id
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module Shoulda # :nodoc:
|
|||
# These helpers will test most of the validations and associations for your ActiveRecord models.
|
||||
#
|
||||
# class UserTest < Test::Unit::TestCase
|
||||
# should_require_attributes :name, :phone_number
|
||||
# should_validate_presence_of :name, :phone_number
|
||||
# should_not_allow_values_for :phone_number, "abcd", "1234"
|
||||
# should_allow_values_for :phone_number, "(123) 456-7890"
|
||||
#
|
||||
|
@ -42,9 +42,9 @@ module Shoulda # :nodoc:
|
|||
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.blank')</tt>
|
||||
#
|
||||
# Example:
|
||||
# should_require_attributes :name, :phone_number
|
||||
# should_validate_presence_of :name, :phone_number
|
||||
#
|
||||
def should_require_attributes(*attributes)
|
||||
def should_validate_presence_of(*attributes)
|
||||
message = get_options!(attributes, :message)
|
||||
klass = model_class
|
||||
|
||||
|
@ -55,6 +55,12 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def should_require_attributes(*attributes)
|
||||
warn "[DEPRECATION] should_require_attributes is deprecated. " <<
|
||||
"Use should_validate_presence_of instead."
|
||||
should_validate_presence_of(*attributes)
|
||||
end
|
||||
|
||||
# Ensures that the model cannot be saved if one of the attributes listed is not unique.
|
||||
# Requires an existing record
|
||||
|
|
|
@ -8,7 +8,7 @@ module Shoulda
|
|||
# example, to ensure that a set of test macros should fail, do this:
|
||||
#
|
||||
# should_fail do
|
||||
# should_require_attributes :comments
|
||||
# should_validate_presence_of :comments
|
||||
# should_protect_attributes :name
|
||||
# end
|
||||
def should_fail(&block)
|
||||
|
|
|
@ -6,5 +6,5 @@ class Pets::DogTest < Test::Unit::TestCase
|
|||
should_have_many :treats
|
||||
should_have_and_belong_to_many :fleas
|
||||
should_require_attributes :treats, :fleas
|
||||
should_require_attributes :owner_id
|
||||
should_validate_presence_of :owner_id
|
||||
end
|
||||
|
|
|
@ -9,8 +9,8 @@ class PostTest < Test::Unit::TestCase
|
|||
should_have_many :through_tags, :through => :taggings
|
||||
|
||||
should_require_unique_attributes :title
|
||||
should_require_attributes :body, :message => /wtf/
|
||||
should_require_attributes :title
|
||||
should_validate_presence_of :body, :message => /wtf/
|
||||
should_validate_presence_of :title
|
||||
should_only_allow_numeric_values_for :user_id
|
||||
|
||||
should_fail do
|
||||
|
|
|
@ -6,7 +6,7 @@ class ProductTest < ActiveSupport::TestCase
|
|||
@product = Product.new(:tangible => false)
|
||||
end
|
||||
|
||||
should_require_attributes :title
|
||||
should_validate_presence_of :title
|
||||
should_not_allow_values_for :size, "22"
|
||||
should_allow_values_for :size, "22kb"
|
||||
should_ensure_value_in_range :price, 0..99
|
||||
|
@ -17,7 +17,7 @@ class ProductTest < ActiveSupport::TestCase
|
|||
@product = Product.new(:tangible => true)
|
||||
end
|
||||
|
||||
should_require_attributes :price
|
||||
should_validate_presence_of :price
|
||||
should_ensure_value_in_range :price, 1..9999
|
||||
should_ensure_value_in_range :weight, 1..100
|
||||
should_not_allow_values_for :size, "22", "10x15"
|
||||
|
|
Loading…
Reference in New Issue