
Validations should throw an exception if a specified context does not exist
Reported by Carl Lerche | June 11th, 2008 @ 04:34 PM
I would like to suggest that when validations are being run and a context is specified that does not exist, then an exception should be raised. This would prevent data to become corrupt because a typo was made somewhere and invalid data was saved.
user = User.new
user.valid(:bogus_context) # => Should raise an exception
I would also like to suggest that a default context :none should created where no validations are run. This is assuming that save still runs validations by default.
Comments and changes to this ticket
-
Dan Kubb (dkubb) June 11th, 2008 @ 04:40 PM
- Milestone cleared.
- State changed from new to open
I agree using a non-defined context should raise an Exception.
One thing Sam and I were discussing is making a Resource#save! that bypasses validations. I know this breaks with the AR convention, but it is more inline with the Ruby convention of having the "!" version of a method be the unsafe version.
-
Adam French June 12th, 2008 @ 11:11 AM
- State changed from open to resolved
- Assigned user changed from Sam Smoot to Adam French
I just added this in. It raises an ArgumentError if there are contexts defined but no context of that name available. If there isn't any contexts defined, and you supplied one, it just silently falls back to :default
-
Carl Lerche June 12th, 2008 @ 05:47 PM
Just as a note, as per our chat on IRC, I made it throw the ArgumentError if the context_name is nil or false (since we don't want save(nil | false) to save without running validations).
#save! is the correct method for this.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »