Skip to content
Browse files

length validation for fixnums

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 3a22e74 commit 01cb81a66f815a30452b850cd63d89bed30953a9 @andriytyurnikov andriytyurnikov committed with spastorino Mar 10, 2011
View
3 activemodel/lib/active_model/validations/length.rb
@@ -42,7 +42,8 @@ def validate_each(record, attribute, value)
next unless check_value = options[key]
value ||= [] if key == :maximum
-
+
+ next if value.kind_of?(Fixnum) && value.to_s.size.send(validity_check, check_value)
next if value && value.size.send(validity_check, check_value)
errors_options = options.except(*RESERVED_OPTIONS)
View
11 activemodel/test/cases/validations/length_validation_test.rb
@@ -341,6 +341,17 @@ def test_validates_length_of_with_block
assert t.errors[:content].any?
assert_equal ["Your essay must be at least 5 words."], t.errors[:content]
end
+
+ def test_validates_length_of_for_fixnum
+ Topic.validates_length_of(:approved, :is => 4)
+
+ t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1)
+ assert t.invalid?
+ assert t.errors[:approved].any?
+
+ t = Topic.new("title" => "uhohuhoh", "content" => "whatever", :approved => 1234)
+ assert t.valid?
+ end
def test_validates_length_of_for_ruby_class
Person.validates_length_of :karma, :minimum => 5

0 comments on commit 01cb81a

Please sign in to comment.
Something went wrong with that request. Please try again.