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
Elliot Winkler 9d9dc4e6b9 Tighten CouldNotSetAttributeError restriction
Why:

* Previously, `allow_value` would raise a CouldNotSetAttributeError
  if the value being set didn't match the value the attribute had after
  being set, but only if the attribute was being changed from nil to
  non-nil or non-nil to nil.
* It turns out it doesn't matter which value you're trying to set the
  attribute to -- if the attribute rejects that change it's confusing
  either way. (In fact, I was recently bit by a case in which I was
  trying to validate numericality of an attribute, where the writer
  method for that attribute was overridden to ensure that the attribute
  always stored a number and never contained non-number characters.
  This ended up making the numericality validation useless, of
  course -- but it caused confusion because the test acted in a way
  I didn't expect.)

To satisfy the above:

* `allow_value` now raises a CouldNotSetAttributeError if the attribute
  rejects the value being set in *any* way.
* However, add a `ignoring_interference_by_writer` qualifier so that
  it is possible to manually override this behavior.
* Fix tests that are failing now because of this new change:
  * Fix tests for allow_value matcher
  * Fix tests for numericality matcher
  * Remove tests for numericality matcher + integer column
    * An integer column will typecast any non-integer value to an
      integer.
    * Because of the typecasting, our tests for the numericality matcher
      against an integer column don't quite work, because we can't
      really test what happens when the attribute is set to a
      non-integer value. Now that `allow_value` is more strict, we're
      getting a CouldNotSetAttributeError when attempting to do so.
    * The tests mentioned were originally added to ensure that we are
      handling RangeErrors that ActiveRecord used to emit. This doesn't
      happen anymore, so the tests aren't necessary anymore either.
  * Fix tests for acceptance matcher
  * Fix tests for absence matcher
2015-09-27 14:56:59 -06:00
..
acceptance Allow the use of matchers from multiple libs, for non rails projects. 2015-06-01 00:43:07 -06:00
support Stop handling AR RangeError when assign a attribute 2015-09-23 15:46:32 -06:00
unit/shoulda/matchers Tighten CouldNotSetAttributeError restriction 2015-09-27 14:56:59 -06:00
warnings_spy Be better about looking for warnings on Travis 2014-12-16 20:30:05 -07:00
acceptance_spec_helper.rb Use pry-byebug instead of pry-nav 2015-04-02 20:13:33 -06:00
doublespeak_spec_helper.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00
report_warnings.rb Remove all Ruby-emitted warnings 2014-07-18 18:00:08 -06:00
unit_spec_helper.rb Run formatter documentation when running a single file 2015-06-13 10:37:31 -03:00
warnings_spy.rb Fail build if there are warnings 2015-02-09 10:48:49 -07:00