Skip to content

Instantly share code, notes, and snippets.

@xHire
Created October 31, 2012 08:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xHire/3985883 to your computer and use it in GitHub Desktop.
Patch for Rails pull request #7282
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment