public
Created

Patch for Rails pull request #7282

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index f529b71..c8fce49 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -45,7 +45,7 @@ module ActiveModel
CHECKS.each do |key, validity_check|
next unless check_value = options[key]
- if !value.nil? || key == :maximum && options[:allow_nil].nil? && options[:allow_blank].nil?
+ if value_is_not_nil_or_nil_is_allowed(value, key, options)
next if value_length.send(validity_check, check_value)
end
@@ -67,6 +67,10 @@ module ActiveModel
end
end
+ def value_is_not_nil_or_nil_is_allowed(value, key, options)
+ !value.nil? || key == :maximum && options[:allow_nil].nil? && options[:allow_blank].nil?
+ end
+
module HelperMethods
# Validates that the specified attribute matches the length restrictions

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.