Add documentation for strict validation testing
This commit is contained in:
parent
1ca1f72a23
commit
fde078da02
|
@ -29,8 +29,19 @@ module Shoulda
|
||||||
# end
|
# end
|
||||||
# it { should allow_value("(123) 456-7890").for(:phone_number) }
|
# it { should allow_value("(123) 456-7890").for(:phone_number) }
|
||||||
# it { should_not allow_mass_assignment_of(:password) }
|
# 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
|
# 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
|
module ActiveModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,9 @@ module Shoulda # :nodoc:
|
||||||
# * <tt>with_message</tt> - value the test expects to find in
|
# * <tt>with_message</tt> - value the test expects to find in
|
||||||
# <tt>errors.on(:attribute)</tt>. Regexp or string. If omitted,
|
# <tt>errors.on(:attribute)</tt>. Regexp or string. If omitted,
|
||||||
# the test looks for any errors in <tt>errors.on(:attribute)</tt>.
|
# 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:
|
# Example:
|
||||||
# it { should_not allow_value('bad').for(:isbn) }
|
# it { should_not allow_value('bad').for(:isbn) }
|
||||||
|
|
Loading…
Reference in New Issue