Skip to content

Commit

Permalink
validates_length_of should not change the options hash in place. [#5283
Browse files Browse the repository at this point in the history
… state:resolved]
  • Loading branch information
josevalim committed Aug 3, 2010
1 parent 257e9c4 commit 79583ca
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions activemodel/lib/active_model/validations/length.rb
Expand Up @@ -40,8 +40,6 @@ def validate_each(record, attribute, value)

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)
Expand All @@ -51,8 +49,13 @@ def validate_each(record, attribute, value)

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
Expand Down

0 comments on commit 79583ca

Please sign in to comment.