-
-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
97 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters