thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model
Elliot Winkler ebe60449ee Fix inclusion to correctly disallow outside values
The inclusion matcher, when qualified with `in_array`, was using
AllowValueMatcher to check that values outside the array were disallowed
by the model (and then inverting its result). However, it should have
been using DisallowValueMatcher all this time. This commit fixes that.

Without this fix, the following error is raised when using the inclusion
matcher against a model which does not have the proper inclusion
validation on it:

    undefined method `attribute_setter' for nil:NilClass

This happens because the inclusion matcher is a complex matcher, i.e.,
it runs a series of submatchers internally and the result of those
submatchers contributes to whether or not the matcher matches. If one of
those submatchers fails, the inclusion matcher immediately fails and
spits out the failure message associated with that submatcher.

However, there is a fundamental difference between AllowValueMatcher and
DisallowValueMatcher as it relates to how they function:

* AllowValueMatcher sets an attribute to a value on a record and expects
  the record not to fail validation.
* DisallowValueMatcher sets an attribute to a value on a record, but
  expects the record *to* fail validation.

The issue in this case is that, because AllowValueMatcher was used
instead of DisallowValueMatcher, the inclusion matcher thought that the
AllowValueMatcher failed, when in fact it passed (this result was just
inverted). So it tried to generate a failure message for a matcher that
didn't fail in the first place. By using DisallowValueMatcher, we set
the proper expectations.
2018-09-15 13:43:30 -03:00
..
allow_value_matcher Remove duplicated method `model` 2018-01-02 14:35:41 -02:00
numericality_matchers Add ignoring_interference_by_writer to all matchers 2016-01-05 00:58:16 -07:00
qualifiers Enable ignoring_interference_by_writer by default 2016-01-05 00:58:17 -07:00
validation_matcher Refactor ValidationMatcher 2015-12-13 20:22:21 -07:00
allow_mass_assignment_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
allow_value_matcher.rb Remove warning from Ruby in AllowValueMatcher 2017-09-17 17:01:50 -05:00
disallow_value_matcher.rb (feature): Add 'ignore_case_sensitivity' option 2016-01-10 21:49:59 -07:00
errors.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
have_secure_password_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
helpers.rb Refactor allow_value & disallow_value 2015-12-13 20:22:22 -07:00
numericality_matchers.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
qualifiers.rb Add ignoring_interference_by_writer to all matchers 2016-01-05 00:58:16 -07:00
validate_absence_of_matcher.rb Revert "Handle uuid columns in validate_absence_of" 2018-09-04 11:17:43 -03:00
validate_acceptance_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
validate_confirmation_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
validate_exclusion_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
validate_inclusion_of_matcher.rb Fix inclusion to correctly disallow outside values 2018-09-15 13:43:30 -03:00
validate_length_of_matcher.rb Add the qualifier allow_nil to validate_length_of 2018-01-24 03:20:05 -06:00
validate_numericality_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
validate_presence_of_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
validation_matcher.rb Add ignoring_interference_by_writer to all matchers 2016-01-05 00:58:16 -07:00
validation_message_finder.rb Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3 2015-02-09 10:52:22 -07:00
validator.rb allow_value: pre-set attributes before validation 2015-12-30 21:34:02 -05:00