diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 19:08:39 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 19:08:39 +0100 |
commit | c6fe49b00921cda55af2dc311dd432795c4313f5 (patch) | |
tree | 9969d333e131dd2a795a10522151580ef69ef7ad /activemodel | |
parent | 5ab94b2595836fe2de36fd632ba9577c459b1292 (diff) | |
download | rails-c6fe49b00921cda55af2dc311dd432795c4313f5.tar.gz rails-c6fe49b00921cda55af2dc311dd432795c4313f5.tar.bz2 rails-c6fe49b00921cda55af2dc311dd432795c4313f5.zip |
Simplyfy validates_length_of and remove puts
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/validations/length.rb | 11 | ||||
-rw-r--r-- | activemodel/test/cases/validations/length_validation_test.rb | 1 |
2 files changed, 7 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index 81c97238d2..3e76796355 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -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 diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index bc24900ecf..499f6a5e31 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -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 |