Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

properly deprecate #{type}_validation_on_#{on}

  • Loading branch information...
commit 9ae7f04cd6c1cdbdd6454448b25302b584860ef6 1 parent 1318bf6
@wycats wycats authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 activemodel/lib/active_model/validations/callbacks.rb
View
14 activemodel/lib/active_model/validations/callbacks.rb
@@ -44,6 +44,20 @@ def after_validation(*args, &block)
options[:if] << "self.validation_context == :#{options[:on]}" if options[:on]
set_callback(:validation, :after, *(args << options), &block)
end
+
+ [:before, :after].each do |type|
+ [:create, :update].each do |on|
+ class_eval <<-RUBY
+ def #{type}_validation_on_#{on}(*args, &block)
+ msg = "#{type}_validation_on_#{on} is deprecated. Please use #{type}_validation(arguments, :on => :#{on}"
+ ActiveSupport::Deprecation.warn(msg, caller)
+ options = args.extract_options!
+ options[:on] = :#{on}
+ before_validation(args.push(options), &block)
+ end
+ RUBY
+ end
+ end
end
protected
Please sign in to comment.
Something went wrong with that request. Please try again.