Commit Graph

6 Commits

Author SHA1 Message Date
Elliot Winkler 5532f4359a Enable ignoring_interference_by_writer by default
Forcing people to add ignoring_interference_by_writer for each and every
case in which an attribute changes incoming values is pretty obnoxious
on our part (for instance, when using the numericality matcher against
an integer column + `only_integer`). So now, it's enabled by default.
This effectively means that people should never get
AtttributeChangedValueErrors again.
2016-01-05 00:58:17 -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 bffc9c9b73 Refactor numericality matcher
This is part of a collection of commits that aim to improve failure
messages across the board. The goal here is to make the matcher easier
to debug when something goes wrong.

* Have the failure message describe what the matcher was trying to do
  when it failed.
* Make the description of the matcher more readable.
* Change how the matcher works by stopping at the first failing
  submatcher instead of running all submatchers. Coincidentally, pending
  tests involving a strict validation but a non-strict expectation now
  pass.
* 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
Mauro George c6cc26d4fe Fix the set_flash matcher to accept a symbol as a param
This is a regression bug fix, on the previous version the matcher
accepts a string or a symbol as a param.

This commit brings back this behavior.
2015-09-29 22:07:50 -06:00
Elliot Winkler 535fe05be8 Consolidate set_session and set_flash APIs
* Refactor so they both use SetSessionOrFlashMatcher internally
* Remove `set_session['key']` in favor of `set_session('key')`
* `set_flash['key'].to(nil)` no longer works if set_flash has never been
  set
2015-02-09 10:52:51 -07:00
Elliot Winkler bbdf8a807e Reorganize unit tests, part I
* Move spec/shoulda to spec/unit_tests/shoulda
* Move spec/support/*.rb to spec/support/unit_tests/{helpers,matchers}
* Move spec_helper.rb to unit_spec_helper.rb
2014-11-04 14:43:59 -07:00