diff --git a/lib/shoulda/matchers/active_model.rb b/lib/shoulda/matchers/active_model.rb index e32906a3..8c8f32fa 100644 --- a/lib/shoulda/matchers/active_model.rb +++ b/lib/shoulda/matchers/active_model.rb @@ -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 diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher.rb b/lib/shoulda/matchers/active_model/allow_value_matcher.rb index 967b372a..4826ad8d 100644 --- a/lib/shoulda/matchers/active_model/allow_value_matcher.rb +++ b/lib/shoulda/matchers/active_model/allow_value_matcher.rb @@ -11,6 +11,9 @@ module Shoulda # :nodoc: # * with_message - value the test expects to find in # errors.on(:attribute). Regexp or string. If omitted, # the test looks for any errors in errors.on(:attribute). + # * strict - 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) }