aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorJohn Foley <john@thefol.io>2012-07-02 10:18:12 -0600
committerJohn Foley <john@thefol.io>2012-09-23 12:53:50 -0600
commitd66d6076b2a723c72d97fb8e8f90d83249f9bfe5 (patch)
treee5136d7466ff78671f6d999cb5a8ca0c01b1faf2 /activemodel
parent09d298eeccd46857dd018aea7ba0a880640cc289 (diff)
downloadrails-d66d6076b2a723c72d97fb8e8f90d83249f9bfe5.tar.gz
rails-d66d6076b2a723c72d97fb8e8f90d83249f9bfe5.tar.bz2
rails-d66d6076b2a723c72d97fb8e8f90d83249f9bfe5.zip
Fix collisions with before and after validation callbacks.
This commit allows a user to do something like: before_validation :do_stuff, :on => [ :create, :update ] after_validation :do_more, :on => [ :create, :update ]
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations/callbacks.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb
index bf3fe7ff04..c59babd831 100644
--- a/activemodel/lib/active_model/validations/callbacks.rb
+++ b/activemodel/lib/active_model/validations/callbacks.rb
@@ -56,7 +56,8 @@ module ActiveModel
options = args.last
if options.is_a?(Hash) && options[:on]
options[:if] = Array(options[:if])
- options[:if].unshift("self.validation_context == :#{options[:on]}")
+ options[:on] = Array(options[:on])
+ options[:if].unshift("self.validation_context.in? #{options[:on]}")
end
set_callback(:validation, :before, *args, &block)
end
@@ -92,7 +93,10 @@ module ActiveModel
options = args.extract_options!
options[:prepend] = true
options[:if] = Array(options[:if])
- options[:if].unshift("self.validation_context == :#{options[:on]}") if options[:on]
+ if options[:on]
+ options[:on] = Array(options[:on])
+ options[:if].unshift("self.validation_context.in? #{options[:on]}")
+ end
set_callback(:validation, :after, *(args << options), &block)
end
end