From 60dad828aefa41703c0eee3863a7141c56caa7da Mon Sep 17 00:00:00 2001
From: Niels Ganser <niels@herimedia.com>
Date: Mon, 6 Feb 2012 12:56:38 +0100
Subject: =?UTF-8?q?To=20infinity=E2=80=A6=20and=20beyond!?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Allow infinite values for validates_length_of. Particularly useful
for prettily defining an open ended range such as

validates_length_of :human_stupidity, :within => 0..Float::INFINITY
---
 .../test/cases/validations/length_validation_test.rb   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'activemodel/test')

diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb
index aa86d9d959..113bfd6337 100644
--- a/activemodel/test/cases/validations/length_validation_test.rb
+++ b/activemodel/test/cases/validations/length_validation_test.rb
@@ -357,4 +357,22 @@ class LengthValidationTest < ActiveModel::TestCase
   ensure
     Person.reset_callbacks(:validate)
   end
+
+  def test_validates_length_of_for_infinite_maxima
+    Topic.validates_length_of(:title, :within => 5..Float::INFINITY)
+
+    t = Topic.new("title" => "1234")
+    assert t.invalid?
+    assert t.errors[:title].any?
+
+    t.title = "12345"
+    assert t.valid?
+
+    Topic.validates_length_of(:author_name, :maximum => Float::INFINITY)
+
+    assert t.valid?
+
+    t.author_name = "A very long author name that should still be valid." * 100
+    assert t.valid?
+  end
 end
-- 
cgit v1.2.3