Skip to content

Commit

Permalink
Add documentation for strict validation testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Sep 14, 2012
1 parent 1ca1f72 commit fde078d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/shoulda/matchers/active_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/shoulda/matchers/active_model/allow_value_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit fde078d

Please sign in to comment.