diff options
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 3 | ||||
-rw-r--r-- | activemodel/lib/active_model/validator.rb | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 7af6c83460..72735cfb89 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -43,7 +43,8 @@ module ActiveModel value ||= [] if key == :maximum - next if value && value.size.send(validity_check, check_value) + value_length = value.respond_to?(:length) ? value.length : value.to_s.length + next if value_length.send(validity_check, check_value) errors_options = options.except(*RESERVED_OPTIONS) errors_options[:count] = check_value diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 1c6123eb09..c5ed8d22d3 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -120,7 +120,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with validation logic, adding errors # to the records +errors+ array where necessary. def validate(record) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate(record) method." end end @@ -156,7 +156,7 @@ module ActiveModel #:nodoc: # Override this method in subclasses with the validation logic, adding # errors to the records +errors+ array where necessary. def validate_each(record, attribute, value) - raise NotImplementedError + raise NotImplementedError, "Subclasses must implement a validate_each(record, attribute, value) method" end # Hook method that gets called by the initializer allowing verification |