diff options
author | Lucas Mazza <lucastmazza@gmail.com> | 2015-02-20 15:50:49 -0200 |
---|---|---|
committer | Lucas Mazza <lucastmazza@gmail.com> | 2015-02-20 16:05:26 -0200 |
commit | 830b7041f213669c3877edf459ef83a31c84cc4d (patch) | |
tree | 8bd42086a0c466958d5e31703a8c100e9c419d9d /activerecord | |
parent | 85388885d7fc11e2cb2d33e46ac606e4f12ea853 (diff) | |
download | rails-830b7041f213669c3877edf459ef83a31c84cc4d.tar.gz rails-830b7041f213669c3877edf459ef83a31c84cc4d.tar.bz2 rails-830b7041f213669c3877edf459ef83a31c84cc4d.zip |
Move the `validate!` method to `ActiveModel::Validations`.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index f27adc9c40..e227212827 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -40,7 +40,7 @@ module ActiveRecord # Attempts to save the record just like Base#save but will raise a +RecordInvalid+ # exception instead of returning +false+ if the record is not valid. def save!(options={}) - perform_validations(options) ? super : raise_record_invalid + perform_validations(options) ? super : raise_validation_error end # Runs all the validations within the specified context. Returns +true+ if @@ -61,21 +61,9 @@ module ActiveRecord alias_method :validate, :valid? - # Runs all the validations within the specified context. Returns +true+ if - # no errors are found, raises +RecordInvalid+ otherwise. - # - # If the argument is +false+ (default is +nil+), the context is set to <tt>:create</tt> if - # <tt>new_record?</tt> is +true+, and to <tt>:update</tt> if it is not. - # - # Validations with no <tt>:on</tt> option will run no matter the context. Validations with - # some <tt>:on</tt> option will only run in the specified context. - def validate!(context = nil) - valid?(context) || raise_record_invalid - end - protected - def raise_record_invalid + def raise_validation_error raise(RecordInvalid.new(self)) end |