Add documentation for strict validation testing

This commit is contained in:
Joe Ferris 2012-09-14 09:59:24 -04:00
parent 1ca1f72a23
commit fde078da02
2 changed files with 14 additions and 0 deletions

View File

@ -29,8 +29,19 @@ module Shoulda
# end
# it { should allow_value("(123) 456-7890").for(:phone_number) }
# it { should_not allow_mass_assignment_of(:password) }
# it { should allow_value('Activated', 'Pending').for(:status).strict }
# it { should_not allow_value('Amazing').for(:status).strict }
# end
#
# These tests work with the following model:
#
# class User < ActiveRecord::Base
# validates_presence_of :name
# validates_presence_of :phone_number
# validates_format_of :phone_number, :with => /\\(\\d{3}\\) \\d{3}\\-\\d{4}/
# validates_inclusion_of :status, :in => %w(Activated Pending), :strict => true
# attr_accessible :name, :phone_number
# end
module ActiveModel
end
end

View File

@ -11,6 +11,9 @@ module Shoulda # :nodoc:
# * <tt>with_message</tt> - value the test expects to find in
# <tt>errors.on(:attribute)</tt>. Regexp or string. If omitted,
# the test looks for any errors in <tt>errors.on(:attribute)</tt>.
# * <tt>strict</tt> - expects the model to raise an exception when the
# validation fails rather than adding to the errors collection. Used for
# testing `validates!` and the `:strict => true` validation options.
#
# Example:
# it { should_not allow_value('bad').for(:isbn) }