diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 18:39:44 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 18:39:44 +0100 |
commit | 2e50110eac439f3d5d292f1519ae7c79991eb91a (patch) | |
tree | 5ba10ebd6ddf0a7487754798993d3862ee9ec3b3 /activemodel/test/cases/validations/length_validation_test.rb | |
parent | a7f09bc12236d9e7bdc2ee34d5fe3c782d6ad385 (diff) | |
parent | bb1e1776914edf3be7e46b55036c18a64595f919 (diff) | |
download | rails-2e50110eac439f3d5d292f1519ae7c79991eb91a.tar.gz rails-2e50110eac439f3d5d292f1519ae7c79991eb91a.tar.bz2 rails-2e50110eac439f3d5d292f1519ae7c79991eb91a.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'activemodel/test/cases/validations/length_validation_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/length_validation_test.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 4a2f72feab..2c97b762f1 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -52,6 +52,12 @@ class LengthValidationTest < ActiveModel::TestCase assert_equal ["is too short (minimum is 5 characters)"], t.errors["title"] end + def test_validates_length_of_using_maximum_should_allow_nil + Topic.validates_length_of :title, :maximum => 10 + t = Topic.create + assert t.valid? + end + def test_optionally_validates_length_of_using_minimum Topic.validates_length_of :title, :minimum => 5, :allow_nil => true @@ -75,9 +81,6 @@ class LengthValidationTest < ActiveModel::TestCase t.title = "" assert t.valid? - - t.title = nil - assert !t.valid? end def test_optionally_validates_length_of_using_maximum @@ -109,6 +112,20 @@ class LengthValidationTest < ActiveModel::TestCase assert t.valid? end + def test_validates_length_of_using_within_with_exclusive_range + Topic.validates_length_of(:title, :within => 4...10) + + t = Topic.new("title" => "9 chars!!") + assert t.valid? + + t.title = "Now I'm 10" + assert !t.valid? + assert_equal ["is too long (maximum is 9 characters)"], t.errors[:title] + + t.title = "Four" + assert t.valid? + end + def test_optionally_validates_length_of_using_within Topic.validates_length_of :title, :content, :within => 3..5, :allow_nil => true |