aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-08-03 15:34:31 +0200
committerJosé Valim <jose.valim@gmail.com>2010-08-03 15:36:23 +0200
commit84081fcc548b309a79580b03aab6a39b726e0b03 (patch)
treee7073ea61c2882abef5d8189db095f1ff1699057
parentf23bc8444b1f1193b2f9135474545436be97b195 (diff)
downloadrails-84081fcc548b309a79580b03aab6a39b726e0b03.tar.gz
rails-84081fcc548b309a79580b03aab6a39b726e0b03.tar.bz2
rails-84081fcc548b309a79580b03aab6a39b726e0b03.zip
Freeze options so we raise an error when people modify it in place.
-rw-r--r--activemodel/lib/active_model/validations.rb6
-rw-r--r--activemodel/lib/active_model/validator.rb2
2 files changed, 5 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 1a58d4c4fb..3407c59e7a 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -118,11 +118,13 @@ module ActiveModel
# 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
diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb
index 52192d5988..163124d531 100644
--- a/activemodel/lib/active_model/validator.rb
+++ b/activemodel/lib/active_model/validator.rb
@@ -111,7 +111,7 @@ module ActiveModel #:nodoc:
# 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.