module Shoulda::ActiveRecord::Matchers
def validate_uniqueness_of(attr)
it { should validate_uniqueness_of(:keyword).case_insensitive }
scoped_to(:first_name, :last_name) }
it { should validate_uniqueness_of(:email).
it { should validate_uniqueness_of(:email).scoped_to(:name) }
it { should validate_uniqueness_of(:keyword).with_message(/dup/) }
it { should validate_uniqueness_of(:keyword) }
Examples:
check case. Off by default. Ignored by non-text attributes.
* case_insensitive - ensures that the validation does not
* scoped_to - field(s) to scope the uniqueness to.
Defaults to the translation for :taken.
errors.on(:attribute). Regexp or String.
* with_message - value the test expects to find in
Options:
end
it { should validate_uniqueness_of(:email) }
before(:each) { User.create!(:email => 'address@example.com') }
describe User do
the model being tested, like so:
so this will always fail if you have not saved at least one record for
Internally, this uses values from existing records to test validations,
Ensures that the model is invalid if the given attribute is not unique.
def validate_uniqueness_of(attr) ValidateUniquenessOfMatcher.new(attr) end