diff options
Diffstat (limited to 'activemodel/test/cases/validations')
-rw-r--r-- | activemodel/test/cases/validations/length_validation_test.rb | 23 | ||||
-rw-r--r-- | activemodel/test/cases/validations/presence_validation_test.rb | 14 |
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 |