Permalink
Browse files

Renamed matchers in accordance with ticket #106

  • Loading branch information...
1 parent f732ae6 commit 3a07c1f5aa072a7d9b669b9a0a50f510f24d97ea @jferris jferris committed Jan 27, 2009
@@ -49,7 +49,7 @@ def should_require_attributes(*attributes)
klass = model_class
attributes.each do |attribute|
- matcher = require_attribute(attribute).with_message(message)
+ matcher = validate_presence_of(attribute).with_message(message)
should matcher.description do
assert_accepts(matcher, get_instance_of(klass))
end
@@ -82,7 +82,7 @@ def should_require_unique_attributes(*attributes)
klass = model_class
attributes.each do |attribute|
- matcher = require_unique_attribute(attribute).
+ matcher = validate_uniqueness_of(attribute).
with_message(message).scoped_to(scope)
matcher = matcher.case_insensitive unless case_sensitive
should matcher.description do
@@ -296,7 +296,7 @@ def should_only_allow_numeric_values_for(*attributes)
message = get_options!(attributes, :message)
klass = model_class
attributes.each do |attribute|
- matcher = only_allow_numeric_values_for(attribute).
+ matcher = validate_numericality_of(attribute).
with_message(message)
should matcher.description do
assert_accepts matcher, get_instance_of(klass)
@@ -489,7 +489,7 @@ def should_require_acceptance_of(*attributes)
klass = model_class
attributes.each do |attribute|
- matcher = require_acceptance_of(attribute).with_message(message)
+ matcher = validate_acceptance_of(attribute).with_message(message)
should matcher.description do
assert_accepts matcher, get_instance_of(klass)
end
@@ -3,10 +3,10 @@
require 'shoulda/active_record/matchers/allow_value_matcher'
require 'shoulda/active_record/matchers/ensure_length_of_matcher'
require 'shoulda/active_record/matchers/ensure_inclusion_of_matcher'
-require 'shoulda/active_record/matchers/require_attribute_matcher'
-require 'shoulda/active_record/matchers/require_unique_attribute_matcher'
-require 'shoulda/active_record/matchers/require_acceptance_of_matcher'
-require 'shoulda/active_record/matchers/only_allow_numeric_values_matcher'
+require 'shoulda/active_record/matchers/validate_presence_of_matcher'
+require 'shoulda/active_record/matchers/validate_uniqueness_of_matcher'
+require 'shoulda/active_record/matchers/validate_acceptance_of_matcher'
+require 'shoulda/active_record/matchers/validate_numericality_of_matcher'
require 'shoulda/active_record/matchers/association_matcher'
require 'shoulda/active_record/matchers/have_db_column_matcher'
require 'shoulda/active_record/matchers/have_index_matcher'
@@ -23,8 +23,8 @@ module ActiveRecord # :nodoc:
# ActiveRecord models.
#
# describe User do
- # it { should require_attribute(:name) }
- # it { should require_attribute(:phone_number) }
+ # it { should validate_presence_of(:name) }
+ # it { should validate_presence_of(:phone_number) }
# %w(abcd 1234).each do |value|
# it { should_not allow_value(value).for(:phone_number) }
# end
@@ -11,14 +11,13 @@ module Matchers
# translation for <tt>:accepted</tt>.
#
# Example:
- # it { should require_acceptance_of(:eula) }
+ # it { should validate_acceptance_of(:eula) }
#
- def require_acceptance_of(attr)
- RequireAcceptanceOfMatcher.
- new(attr)
+ def validate_acceptance_of(attr)
+ ValidateAcceptanceOfMatcher.new(attr)
end
- class RequireAcceptanceOfMatcher < ValidationMatcher # :nodoc:
+ class ValidateAcceptanceOfMatcher < ValidationMatcher # :nodoc:
def with_message(message)
@expected_message = message if message
@@ -10,13 +10,13 @@ module Matchers
# translation for <tt>:not_a_number</tt>.
#
# Example:
- # it { should only_allow_numeric_values_for(:age) }
+ # it { should validate_numericality_of(:age) }
#
- def only_allow_numeric_values_for(attr)
- OnlyAllowNumericValuesMatcher.new(attr)
+ def validate_numericality_of(attr)
+ ValidateNumericalityOfMatcher.new(attr)
end
- class OnlyAllowNumericValuesMatcher < ValidationMatcher # :nodoc:
+ class ValidateNumericalityOfMatcher < ValidationMatcher # :nodoc:
def with_message(message)
@expected_message = message if message
@@ -11,15 +11,15 @@ module Matchers
# Defaults to the translation for <tt>:blank</tt>.
#
# Examples:
- # it { should require_attribute(:name) }
- # it { should require_attribute(:name).with_message(/is not optional/) }
+ # it { should validate_presence_of(:name) }
+ # it { should validate_presence_of(:name).
+ # with_message(/is not optional/) }
#
- def require_attribute(attr)
- RequireAttributeMatcher.
- new(attr)
+ def validate_presence_of(attr)
+ ValidatePresenceOfMatcher.new(attr)
end
- class RequireAttributeMatcher < ValidationMatcher # :nodoc:
+ class ValidatePresenceOfMatcher < ValidationMatcher # :nodoc:
def with_message(message)
@expected_message = message if message
@@ -10,7 +10,7 @@ module Matchers
#
# describe User do
# before(:each) { User.create!(:email => 'address@example.com') }
- # it { should require_unique_attribute(:email) }
+ # it { should validate_uniqueness_of(:email) }
# end
#
# Options:
@@ -23,18 +23,18 @@ module Matchers
# check case. Off by default. Ignored by non-text attributes.
#
# Examples:
- # it { should require_unique_attribute(:keyword) }
- # it { should require_unique_attribute(:keyword).with_message(/dup/) }
- # it { should require_unique_attribute(:email).scoped_to(:name) }
- # it { should require_unique_attribute(:email).
+ # it { should validate_uniqueness_of(:keyword) }
+ # it { should validate_uniqueness_of(:keyword).with_message(/dup/) }
+ # it { should validate_uniqueness_of(:email).scoped_to(:name) }
+ # it { should validate_uniqueness_of(:email).
# scoped_to(:first_name, :last_name) }
- # it { should require_unique_attribute(:keyword).case_insensitive }
+ # it { should validate_uniqueness_of(:keyword).case_insensitive }
#
- def require_unique_attribute(attr)
- RequireUniqueAttributeMatcher.new(attr)
+ def validate_uniqueness_of(attr)
+ ValidateUniquenessOfMatcher.new(attr)
end
- class RequireUniqueAttributeMatcher < ValidationMatcher # :nodoc:
+ class ValidateUniquenessOfMatcher < ValidationMatcher # :nodoc:
include Helpers
def initialize(attribute)
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
-class RequireAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc:
+class ValidateAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc:
context "an attribute which must be accepted" do
setup do
@@ -10,11 +10,11 @@ class RequireAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "require that attribute to be accepted" do
- assert_accepts require_acceptance_of(:attr), @model
+ assert_accepts validate_acceptance_of(:attr), @model
end
should "not overwrite the default message with nil" do
- assert_accepts require_acceptance_of(:attr).with_message(nil), @model
+ assert_accepts validate_acceptance_of(:attr).with_message(nil), @model
end
end
@@ -24,7 +24,7 @@ class RequireAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "not require that attribute to be accepted" do
- assert_rejects require_acceptance_of(:attr), @model
+ assert_rejects validate_acceptance_of(:attr), @model
end
end
@@ -36,7 +36,8 @@ class RequireAcceptanceOfMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "require that attribute to be accepted with that message" do
- assert_accepts require_acceptance_of(:attr).with_message(/custom/), @model
+ assert_accepts validate_acceptance_of(:attr).with_message(/custom/),
+ @model
end
end
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
-class OnlyAllowNumericValuesMatcherTest < Test::Unit::TestCase # :nodoc:
+class ValidateNumericalityOfMatcherTest < Test::Unit::TestCase # :nodoc:
context "a numeric attribute" do
setup do
@@ -11,11 +11,11 @@ class OnlyAllowNumericValuesMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "only allow numeric values for that attribute" do
- assert_accepts only_allow_numeric_values_for(:attr), @model
+ assert_accepts validate_numericality_of(:attr), @model
end
should "not override the default message with a blank" do
- assert_accepts only_allow_numeric_values_for(:attr).with_message(nil),
+ assert_accepts validate_numericality_of(:attr).with_message(nil),
@model
end
end
@@ -29,13 +29,13 @@ class OnlyAllowNumericValuesMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "only allow numeric values for that attribute with that message" do
- assert_accepts only_allow_numeric_values_for(:attr).
+ assert_accepts validate_numericality_of(:attr).
with_message(/custom/),
@model
end
should "not allow numeric values for that attribute with another message" do
- assert_rejects only_allow_numeric_values_for(:attr), @model
+ assert_rejects validate_numericality_of(:attr), @model
end
end
@@ -45,7 +45,7 @@ class OnlyAllowNumericValuesMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "not only allow numeric values for that attribute" do
- assert_rejects only_allow_numeric_values_for(:attr), @model
+ assert_rejects validate_numericality_of(:attr), @model
end
end
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper')
-class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
+class ValidatePresenceOfMatcherTest < Test::Unit::TestCase # :nodoc:
context "a required attribute" do
setup do
@@ -11,11 +11,11 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "require a value" do
- assert_accepts require_attribute(:attr), @model
+ assert_accepts validate_presence_of(:attr), @model
end
should "not override the default message with a blank" do
- assert_accepts require_attribute(:attr).with_message(nil), @model
+ assert_accepts validate_presence_of(:attr).with_message(nil), @model
end
end
@@ -25,7 +25,7 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "not require a value" do
- assert_rejects require_attribute(:attr), @model
+ assert_rejects validate_presence_of(:attr), @model
end
end
@@ -39,7 +39,7 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "require the attribute to be set" do
- assert_accepts require_attribute(:children), @model
+ assert_accepts validate_presence_of(:children), @model
end
end
@@ -52,7 +52,7 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "not require the attribute to be set" do
- assert_rejects require_attribute(:children), @model
+ assert_rejects validate_presence_of(:children), @model
end
end
@@ -66,7 +66,7 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "require the attribute to be set" do
- assert_accepts require_attribute(:children), @model
+ assert_accepts validate_presence_of(:children), @model
end
end
@@ -79,7 +79,7 @@ class RequireAttributeMatcherTest < Test::Unit::TestCase # :nodoc:
end
should "not require the attribute to be set" do
- assert_rejects require_attribute(:children), @model
+ assert_rejects validate_presence_of(:children), @model
end
end
Oops, something went wrong.

0 comments on commit 3a07c1f

Please sign in to comment.