1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplyfy validates_length_of and remove puts

This commit is contained in:
Pratik Naik 2009-08-08 19:08:39 +01:00
parent 5ab94b2595
commit c6fe49b009
2 changed files with 7 additions and 5 deletions

View file

@ -80,11 +80,14 @@ module ActiveModel
validates_each(attrs, options) do |record, attr, value|
value = options[:tokenizer].call(value) if value.kind_of?(String)
unless option == :maximum and value.nil?
unless !value.nil? and value.size.send(validity_checks[option], option_value)
record.errors.add(attr, key, :default => custom_message, :count => option_value)
end
valid_value = if option == :maximum
value.nil? || value.size.send(validity_checks[option], option_value)
else
value && value.size.send(validity_checks[option], option_value)
end
record.errors.add(attr, key, :default => custom_message, :count => option_value) unless valid_value
end
end
end

View file

@ -55,7 +55,6 @@ class LengthValidationTest < ActiveModel::TestCase
def test_validates_length_of_using_maximum_should_allow_nil
Topic.validates_length_of :title, :maximum => 10
t = Topic.create
puts t.errors
assert t.valid?
end