aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-09 18:39:44 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-09 18:39:44 +0100
commit2e50110eac439f3d5d292f1519ae7c79991eb91a (patch)
tree5ba10ebd6ddf0a7487754798993d3862ee9ec3b3 /activemodel/test/cases/validations
parenta7f09bc12236d9e7bdc2ee34d5fe3c782d6ad385 (diff)
parentbb1e1776914edf3be7e46b55036c18a64595f919 (diff)
downloadrails-2e50110eac439f3d5d292f1519ae7c79991eb91a.tar.gz
rails-2e50110eac439f3d5d292f1519ae7c79991eb91a.tar.bz2
rails-2e50110eac439f3d5d292f1519ae7c79991eb91a.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activemodel/test/cases/validations')
-rw-r--r--activemodel/test/cases/validations/length_validation_test.rb23
-rw-r--r--activemodel/test/cases/validations/presence_validation_test.rb14
2 files changed, 34 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
diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb
index aa5bdf1e62..bb6fb91774 100644
--- a/activemodel/test/cases/validations/presence_validation_test.rb
+++ b/activemodel/test/cases/validations/presence_validation_test.rb
@@ -54,4 +54,18 @@ class PresenceValidationTest < ActiveModel::TestCase
assert p.valid?
end
end
+
+ def test_validates_presence_of_for_ruby_class_with_custom_reader
+ repair_validations(Person) do
+ CustomReader.validates_presence_of :karma
+
+ p = CustomReader.new
+ assert p.invalid?
+
+ assert_equal ["can't be blank"], p.errors[:karma]
+
+ p[:karma] = "Cold"
+ assert p.valid?
+ end
+ end
end