aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-26 18:44:07 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-26 18:44:07 -0200
commit5658923daa2f2c7858f55844168e1872cc611766 (patch)
tree1cfbb9afc852239dc5f15e67c00022d09a9e50f8 /activemodel/test/cases
parentb3660ac33539e668228acc0e58926201f969a506 (diff)
parentea76e9a3126998578d683783483aa695cb6b657e (diff)
downloadrails-5658923daa2f2c7858f55844168e1872cc611766.tar.gz
rails-5658923daa2f2c7858f55844168e1872cc611766.tar.bz2
rails-5658923daa2f2c7858f55844168e1872cc611766.zip
Merge pull request #7282 from xHire/validates_length_of_fix
Length validation handles correctly nil. Fix #7180 Conflicts: activemodel/CHANGELOG.md
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r--activemodel/test/cases/validations/length_validation_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb
index 113bfd6337..1a40ca8efc 100644
--- a/activemodel/test/cases/validations/length_validation_test.rb
+++ b/activemodel/test/cases/validations/length_validation_test.rb
@@ -375,4 +375,43 @@ class LengthValidationTest < ActiveModel::TestCase
t.author_name = "A very long author name that should still be valid." * 100
assert t.valid?
end
+
+ def test_validates_length_of_using_maximum_should_not_allow_nil_when_nil_not_allowed
+ Topic.validates_length_of :title, :maximum => 10, :allow_nil => false
+ t = Topic.new
+ assert t.invalid?
+ end
+
+ def test_validates_length_of_using_maximum_should_not_allow_nil_and_empty_string_when_blank_not_allowed
+ Topic.validates_length_of :title, :maximum => 10, :allow_blank => false
+ t = Topic.new
+ assert t.invalid?
+
+ t.title = ""
+ assert t.invalid?
+ end
+
+ def test_validates_length_of_using_both_minimum_and_maximum_should_not_allow_nil
+ Topic.validates_length_of :title, :minimum => 5, :maximum => 10
+ t = Topic.new
+ assert t.invalid?
+ end
+
+ def test_validates_length_of_using_minimum_0_should_not_allow_nil
+ Topic.validates_length_of :title, :minimum => 0
+ t = Topic.new
+ assert t.invalid?
+
+ t.title = ""
+ assert t.valid?
+ end
+
+ def test_validates_length_of_using_is_0_should_not_allow_nil
+ Topic.validates_length_of :title, :is => 0
+ t = Topic.new
+ assert t.invalid?
+
+ t.title = ""
+ assert t.valid?
+ end
end