Permalink
Browse files

Add documentation for strict validation testing

  • Loading branch information...
1 parent 1ca1f72 commit fde078da0274f69e6deb8f4cfebe6af54d6906d2 @jferris jferris committed Sep 14, 2012
Showing with 14 additions and 0 deletions.
  1. +11 −0 lib/shoulda/matchers/active_model.rb
  2. +3 −0 lib/shoulda/matchers/active_model/allow_value_matcher.rb
@@ -29,8 +29,19 @@ module Matchers
# 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
@@ -11,6 +11,9 @@ module ActiveModel # :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) }

0 comments on commit fde078d

Please sign in to comment.