Permalink
Browse files

Simplyfy validates_length_of and remove puts

  • Loading branch information...
1 parent 5ab94b2 commit c6fe49b00921cda55af2dc311dd432795c4313f5 @lifo lifo committed Aug 8, 2009
@@ -80,11 +80,14 @@ def validates_length_of(*attrs)
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
@@ -55,7 +55,6 @@ def test_validates_length_of_using_minimum
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

0 comments on commit c6fe49b

Please sign in to comment.