mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Freeze options so we raise an error when people modify it in place.
This commit is contained in:
parent
f23bc8444b
commit
84081fcc54
2 changed files with 5 additions and 3 deletions
|
@ -118,11 +118,13 @@ module ActiveModel
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def validate(*args, &block)
|
def validate(*args, &block)
|
||||||
options = args.last
|
options = args.extract_options!
|
||||||
if options.is_a?(Hash) && options.key?(:on)
|
if options.key?(:on)
|
||||||
|
options = options.dup
|
||||||
options[:if] = Array.wrap(options[:if])
|
options[:if] = Array.wrap(options[:if])
|
||||||
options[:if] << "validation_context == :#{options[:on]}"
|
options[:if] << "validation_context == :#{options[:on]}"
|
||||||
end
|
end
|
||||||
|
args << options
|
||||||
set_callback(:validate, *args, &block)
|
set_callback(:validate, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ module ActiveModel #:nodoc:
|
||||||
|
|
||||||
# Accepts options that will be made available through the +options+ reader.
|
# Accepts options that will be made available through the +options+ reader.
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = options
|
@options = options.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the kind for this validator.
|
# Return the kind for this validator.
|
||||||
|
|
Loading…
Reference in a new issue