thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model
Anthony Navarre + Elliot Winkler eaaa2d83e5 allow_value: Raise error if attr sets value differently
`allow_value` will now raise a CouldNotSetAttribute error if the
attribute in question cannot be changed from a non-nil value to a nil
value, or vice versa. In other words, these are the exact cases in which
the error will occur:

* If you're testing whether the attribute allows `nil`, but the
  attribute detects and ignores nil. (For instance, you have a model
  that `has_secure_password`. This will add a #password= method to your
  model that is defined in a such a way that you cannot clear the
  password by setting it to nil -- nothing happens.)
* If you're testing whether the attribute allows a non-nil value, but
  the attribute fails to set that value. (For instance, you have an
  ActiveRecord model. If ActiveRecord cannot typecast the value in the
  context of the column, then it will do nothing, and the attribute will be
  effectively set to nil.)

What's the reasoning behind this change? Simply put, if you are assuming
that the attribute is changing but in fact it is not, then the test
you're writing isn't the test that actually gets run. We feel that this
is dishonest and produces an invalid test.
2015-02-17 23:09:56 -07:00
..
numericality_matchers Handle RangeErrors emitted now in ActiveRecord 4.2 2015-01-22 21:05:09 -07:00
allow_mass_assignment_of_matcher.rb Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3 2015-02-09 10:52:22 -07:00
allow_value_matcher.rb allow_value: Raise error if attr sets value differently 2015-02-17 23:09:56 -07:00
disallow_value_matcher.rb Prefer protected over private attributes 2014-06-27 14:41:54 -06:00
errors.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
have_secure_password_matcher.rb Prefer protected over private attributes 2014-06-27 14:41:54 -06:00
helpers.rb Handle RangeErrors emitted now in ActiveRecord 4.2 2015-01-22 21:05:09 -07:00
numericality_matchers.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
strict_validator.rb Remove these from the docs 2015-01-22 21:24:05 -07:00
validate_absence_of_matcher.rb validate_absence_of: cast `@attribute` to String 2014-08-14 15:34:18 -04:00
validate_acceptance_of_matcher.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
validate_confirmation_of_matcher.rb Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3 2015-02-09 10:52:22 -07:00
validate_exclusion_of_matcher.rb Remove deprecated matchers 2015-02-09 10:52:51 -07:00
validate_inclusion_of_matcher.rb Remove deprecated matchers 2015-02-09 10:52:51 -07:00
validate_length_of_matcher.rb Remove deprecated matchers 2015-02-09 10:52:51 -07:00
validate_numericality_of_matcher.rb Refactor submatcher logic in numericality matcher 2015-01-22 21:05:08 -07:00
validate_presence_of_matcher.rb allow_value: Raise error if attr sets value differently 2015-02-17 23:09:56 -07:00
validation_matcher.rb Remove all Ruby-emitted warnings 2014-07-18 18:00:08 -06: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 Handle RangeErrors emitted now in ActiveRecord 4.2 2015-01-22 21:05:09 -07:00
validator_with_captured_range_error.rb Remove these from the docs 2015-01-22 21:24:05 -07:00