From 54adccda08403d8ad4df7b4d20040bfb421bc738 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 26 Sep 2005 22:40:51 +0000 Subject: [PATCH] r3603@asus: jeremy | 2005-09-26 19:10:00 -0700 Add unit tests for nil assigned to validates_size_of :attr, :within git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2354 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/validations_test.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index afd11c6d62..32beb7d606 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -396,15 +396,20 @@ class ValidationsTest < Test::Unit::TestCase def test_validates_length_of_using_within Topic.validates_length_of(:title, :content, :within => 3..5) - t = Topic.create("title" => "a!", "content" => "I'm ooooooooh so very long") - assert !t.save - + t = Topic.new("title" => "a!", "content" => "I'm ooooooooh so very long") + assert !t.valid? assert_equal "is too short (min is 3 characters)", t.errors.on(:title) assert_equal "is too long (max is 5 characters)", t.errors.on(:content) + t.title = nil + t.content = nil + assert !t.valid? + assert_equal "is too short (min is 3 characters)", t.errors.on(:title) + assert_equal "is too short (min is 3 characters)", t.errors.on(:content) + t.title = "abe" t.content = "mad" - assert t.save + assert t.valid? end def test_optionally_validates_length_of_using_within @@ -801,4 +806,4 @@ class ValidationsTest < Test::Unit::TestCase r.topic = Topic.find :first assert r.valid? end -end \ No newline at end of file +end