Skip to content

Commit

Permalink
calculate errors_options one time in validate_each
Browse files Browse the repository at this point in the history
errors_options is calculated for every *CHECKS* but it could be
calculated one time  because options and RESERVED_OPTIONS
not change during this cycle
  • Loading branch information
acapilleri committed Aug 3, 2012
1 parent 0c315c7 commit 93b6faf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/validations/length.rb
Expand Up @@ -36,12 +36,12 @@ def check_validity!
def validate_each(record, attribute, value)
value = tokenize(value)
value_length = value.respond_to?(:length) ? value.length : value.to_s.length

errors_options = options.except(*RESERVED_OPTIONS)

CHECKS.each do |key, validity_check|
next unless check_value = options[key]
next if value_length.send(validity_check, check_value)

errors_options = options.except(*RESERVED_OPTIONS)
errors_options[:count] = check_value

default_message = options[MESSAGES[key]]
Expand Down

0 comments on commit 93b6faf

Please sign in to comment.