Permalink
Browse files

deprecate should_require_attributes with warning message. replace wit…

…h should_validate_presence_of.
  • Loading branch information...
1 parent 32b54bd commit 205b897089538ee29410f3e99d0f7ddbf6eb78a2 @croaky croaky committed with jferris Jan 18, 2009
Showing with 17 additions and 11 deletions.
  1. +2 −2 README.rdoc
  2. +9 −3 lib/shoulda/active_record/macros.rb
  3. +1 −1 test/fail_macros.rb
  4. +1 −1 test/unit/dog_test.rb
  5. +2 −2 test/unit/post_test.rb
  6. +2 −2 test/unit/product_test.rb
View
@@ -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 ActiveRecord # :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 @@ def load_all_fixtures
# 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 @@ def should_require_attributes(*attributes)
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
View
@@ -8,7 +8,7 @@ module ClassMethods
# 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)
View
@@ -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
View
@@ -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"

0 comments on commit 205b897

Please sign in to comment.