Skip to content
Browse files

Freeze options so we raise an error when people modify it in place.

  • Loading branch information...
1 parent f23bc84 commit 84081fcc548b309a79580b03aab6a39b726e0b03 @josevalim josevalim committed Aug 3, 2010
Showing with 5 additions and 3 deletions.
  1. +4 −2 activemodel/lib/active_model/validations.rb
  2. +1 −1 activemodel/lib/active_model/validator.rb
View
6 activemodel/lib/active_model/validations.rb
@@ -118,11 +118,13 @@ def validates_each(*attr_names, &block)
# end
#
def validate(*args, &block)
- options = args.last
- if options.is_a?(Hash) && options.key?(:on)
+ options = args.extract_options!
+ if options.key?(:on)
+ options = options.dup
options[:if] = Array.wrap(options[:if])
options[:if] << "validation_context == :#{options[:on]}"
end
+ args << options
set_callback(:validate, *args, &block)
end
View
2 activemodel/lib/active_model/validator.rb
@@ -111,7 +111,7 @@ def self.kind
# Accepts options that will be made available through the +options+ reader.
def initialize(options)
- @options = options
+ @options = options.freeze
end
# Return the kind for this validator.

0 comments on commit 84081fc

Please sign in to comment.
Something went wrong with that request. Please try again.