Commit Graph

14 Commits

Author SHA1 Message Date
Elliot Winkler 663c2f2c4d Remove most docs for ignoring_interference_by_writer
Since `ignoring_interference_by_writer` is on by default now, we don't
need to explicitly document it (unless someone wants to turn it off, but
that's unlikely).

[ci skip]
2016-01-10 23:19:47 -07:00
Elliot Winkler 1189934806 Add ignoring_interference_by_writer to all matchers
`allow_value` matcher is, of course, concerned with setting values on a
particular attribute on a particular record, and then checking that the
record is valid after doing so. That comes with a caveat: if the
attribute is overridden in such a way so that the same value going into
the attribute isn't the same value coming out of it, then `allow_value`
will balk -- it'll say, "I can't do that because that changes how I
work."

That's all well and good, but what the attribute intentionally changes
incoming values? ActiveRecord's typecasting behavior, for instance,
would trigger such an exception. What if the developer needs a way to
get around this? This is where `ignoring_interference_by_writer` comes
into play. You can tack it on to the end of the matcher, and you're free
to go on your way.

So, prior to this commit you could already apply it to `allow_value`,
but now in this commit it also works on any other matcher.

But, one little thing: sometimes using this qualifier isn't going to
work. Perhaps you or something else actually *is* overriding the
attribute to change incoming values in a specific way, and perhaps the
value that comes out makes the record fail validation, and there's
nothing you can do about it. So in this case, even if you're using
`ignoring_interference_by_writer`, we want to inform you about what the
attribute is doing -- what the input and output was. And so we do.
2016-01-05 00:58:16 -07:00
Elliot Winkler 6b3253147a allow_value: Inspect values more clearly
Modify descriptions and failure messages for all matchers by way of
allow_value and put small angle brackets around inspected values. This
is to visually distinguish an inspected value from the rest of the text,
and is especially noticeable for complex values such as an array that
contains an object, particularly if the inspected version of the value
wraps onto another line. It's a little easier to see:

    When attempting to set :attr on Example to ‹[#<Child id:
    nil>]›...

rather than:

    When attempting to set :attr on Example to [#<Child id:
    nil>]...
2015-12-30 21:51:54 -05:00
Elliot Winkler 2e35b3730e Refactor inclusion & exclusion matchers
This is part of a collection of commits that aim to improve failure
messages across the board, in order to make matchers easier to debug
when something goes wrong.

* Make the description of the matcher more readable.
* Add boolean methods to check whether `allow_nil` or `allow_blank` have
  been specified, to conform to the interface that ValidationMatcher
  introduces.
* Fix or fill in tests involving failure messages and descriptions to
  match these changes and recent changes to ValidationMatcher and
  allow_value.
2015-12-13 20:22:22 -07:00
Elliot Winkler 8fa97b4ff3 Fix inclusion matcher w/ date & datetime attrs
Why:

* The inclusion matcher (when used with the `in_array` qualifier) makes
  the assertion that when the attribute is set to a value that is
  outside the given array, the record in question is invalid. The issue
  is that when used with a date or datetime attribute, the arbitrary
  value the matcher chose was a string. This was getting typecast and so
  the matcher was throwing a CouldNotSetAttributeError.

To satisfy the above:

* If the column is a date, use a Date for the arbitrary value
* If the column is a datetime, use a DateTime for the arbitrary value
* If the column is a time, use a Time for the arbitrary value
2015-10-04 16:55:48 -06:00
Elliot Winkler 142366ef16 Refer to Minitest in docs over Test::Unit
Minitest has been used instead of Test::Unit for quite some time now,
let's get with the times.

[ci skip]
2015-09-30 13:18:23 -06:00
Mauro George 9a893f372d Add documentation to validate_inclusion_of on qualifier
[ci skip]
2015-03-28 22:33:44 -06:00
Elliot Winkler 55c8d09bf2 Remove deprecated matchers 2015-02-09 10:52:51 -07:00
Elliot Winkler 5f8c3235d0 Fix validate_inclusion_of + with_message
It did not fail if the given message did not match the message on the
validation itself.
2014-11-18 21:03:06 +08:00
Elliot Winkler c714193528 Tweak warning to be descriptive, not prescriptive
While we do advise against using the validates_inclusion_of or
validates_format_of validations with boolean columns, we won't judge
if you would like to do so.
2014-08-14 14:51:17 -04:00
Elliot Winkler c998907926 Document that validate_inclusion_of may produce a warning 2014-07-25 23:35:46 -06:00
Dave Schweisguth 8376dd2fbf Emit BOOLEAN_ALLOWS_BOOLEAN_MESSAGE regardless of the order of the array of all booleans
Documented ensure_inclusion_of change
2014-07-25 23:35:43 -06:00
Elliot Winkler 15d0cee93b Deprecate ensure_inclusion_of 2014-07-23 19:35:20 -06:00
Maxim Kaschenko 93c2336e98 ensure_inclusion_of => validate_inclusion_of 2014-07-21 23:01:40 -06:00