aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/length.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-08-03 15:22:54 +0200
committerJosé Valim <jose.valim@gmail.com>2010-08-03 15:22:54 +0200
commitf23bc8444b1f1193b2f9135474545436be97b195 (patch)
tree9a5fe0eec217e04884667102746f0cf0726dcfa3 /activemodel/lib/active_model/validations/length.rb
parent621246f997887eccf61c1737c76b1eefc9217263 (diff)
downloadrails-f23bc8444b1f1193b2f9135474545436be97b195.tar.gz
rails-f23bc8444b1f1193b2f9135474545436be97b195.tar.bz2
rails-f23bc8444b1f1193b2f9135474545436be97b195.zip
validates_length_of should not change the options hash in place. [#5283 state:resolved]
Diffstat (limited to 'activemodel/lib/active_model/validations/length.rb')
-rw-r--r--activemodel/lib/active_model/validations/length.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index c8a77ad666..a7af4f2b4d 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -40,8 +40,6 @@ module ActiveModel
CHECKS.each do |key, validity_check|
next unless check_value = options[key]
- default_message = options[MESSAGES[key]]
- options[:message] ||= default_message if default_message
valid_value = if key == :maximum
value.nil? || value.size.send(validity_check, check_value)
@@ -51,8 +49,13 @@ module ActiveModel
next if valid_value
- record.errors.add(attribute, MESSAGES[key],
- options.except(*RESERVED_OPTIONS).merge!(:count => check_value))
+ errors_options = options.except(*RESERVED_OPTIONS)
+ errors_options[:count] = check_value
+
+ default_message = options[MESSAGES[key]]
+ errors_options[:message] ||= default_message if default_message
+
+ record.errors.add(attribute, MESSAGES[key], errors_options)
end
end
end