1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers
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
..
action_controller Use head instead of render: nothing in tests 2017-09-28 01:08:55 -05:00
active_model Fix inclusion to correctly disallow outside values 2018-09-15 13:43:30 -03:00
active_record Fix validates_uniqueness_matcher for integer attributes 2018-04-05 11:14:57 -06:00
doublespeak Doublespeak: Remove usage of deprecated RSpec #ordered method 2017-09-17 17:01:50 -05:00
independent Adding support to allow_nil option for delegate_method matcher 2018-01-24 02:22:19 -06:00
routing Replace the with_port qualifier on route with port option 2018-01-25 22:31:23 -06:00
util word_wrap: Add ability to indent wrapped text 2015-12-13 20:22:21 -07:00
doublespeak_spec.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00