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:
parent
5ab94b2595
commit
c6fe49b009
2 changed files with 7 additions and 5 deletions
|
@ -80,11 +80,14 @@ module ActiveModel
|
||||||
|
|
||||||
validates_each(attrs, options) do |record, attr, value|
|
validates_each(attrs, options) do |record, attr, value|
|
||||||
value = options[:tokenizer].call(value) if value.kind_of?(String)
|
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)
|
valid_value = if option == :maximum
|
||||||
record.errors.add(attr, key, :default => custom_message, :count => option_value)
|
value.nil? || value.size.send(validity_checks[option], option_value)
|
||||||
end
|
else
|
||||||
|
value && value.size.send(validity_checks[option], option_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
record.errors.add(attr, key, :default => custom_message, :count => option_value) unless valid_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,6 @@ class LengthValidationTest < ActiveModel::TestCase
|
||||||
def test_validates_length_of_using_maximum_should_allow_nil
|
def test_validates_length_of_using_maximum_should_allow_nil
|
||||||
Topic.validates_length_of :title, :maximum => 10
|
Topic.validates_length_of :title, :maximum => 10
|
||||||
t = Topic.create
|
t = Topic.create
|
||||||
puts t.errors
|
|
||||||
assert t.valid?
|
assert t.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue