diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2010-05-08 23:27:49 +0300 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-05-08 23:51:36 +0300 |
commit | 66913a76af9969ddf12021992eeb418e270bebe2 (patch) | |
tree | 8ff5d8cf518f086979fd4e4b0633c7f8c340323e /activemodel/test/cases/validations/conditional_validation_test.rb | |
parent | 82485068f8b64a49cbb6529d17dd5de27c28e951 (diff) | |
download | rails-66913a76af9969ddf12021992eeb418e270bebe2.tar.gz rails-66913a76af9969ddf12021992eeb418e270bebe2.tar.bz2 rails-66913a76af9969ddf12021992eeb418e270bebe2.zip |
removed use of AR in AMo tests and removed testing of scopes (:on) in individual validation tests and moved them to their own test file
Diffstat (limited to 'activemodel/test/cases/validations/conditional_validation_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/conditional_validation_test.rb | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/activemodel/test/cases/validations/conditional_validation_test.rb b/activemodel/test/cases/validations/conditional_validation_test.rb index 6866bfcf24..6bb5752702 100644 --- a/activemodel/test/cases/validations/conditional_validation_test.rb +++ b/activemodel/test/cases/validations/conditional_validation_test.rb @@ -10,12 +10,12 @@ class ConditionalValidationTest < ActiveModel::TestCase def teardown Topic.reset_callbacks(:validate) end - + def test_if_validation_using_method_true # When the method returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => :condition_is_true ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -23,15 +23,15 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_unless_validation_using_method_true # When the method returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => :condition_is_true ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? - assert !t.errors[:title].any? + assert t.errors[:title].empty? end def test_if_validation_using_method_false # When the method returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => :condition_is_true_but_its_not ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? assert t.errors[:title].empty? end @@ -39,8 +39,8 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_unless_validation_using_method_false # When the method returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => :condition_is_true_but_its_not ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -48,8 +48,8 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_if_validation_using_string_true # When the evaluated string returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => "a = 1; a == 1" ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -57,7 +57,7 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_unless_validation_using_string_true # When the evaluated string returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => "a = 1; a == 1" ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? assert t.errors[:title].empty? end @@ -65,7 +65,7 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_if_validation_using_string_false # When the evaluated string returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => "false") - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? assert t.errors[:title].empty? end @@ -73,8 +73,8 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_unless_validation_using_string_false # When the evaluated string returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => "false") - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -83,8 +83,8 @@ class ConditionalValidationTest < ActiveModel::TestCase # When the block returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => Proc.new { |r| r.content.size > 4 } ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -93,7 +93,7 @@ class ConditionalValidationTest < ActiveModel::TestCase # When the block returns true Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => Proc.new { |r| r.content.size > 4 } ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? assert t.errors[:title].empty? end @@ -102,7 +102,7 @@ class ConditionalValidationTest < ActiveModel::TestCase # When the block returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :if => Proc.new { |r| r.title != "uhohuhoh"} ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.valid? assert t.errors[:title].empty? end @@ -111,8 +111,8 @@ class ConditionalValidationTest < ActiveModel::TestCase # When the block returns false Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %{count}", :unless => Proc.new { |r| r.title != "uhohuhoh"} ) - t = Topic.create("title" => "uhohuhoh", "content" => "whatever") - assert !t.valid? + t = Topic.new("title" => "uhohuhoh", "content" => "whatever") + assert t.invalid? assert t.errors[:title].any? assert_equal ["hoo 5"], t.errors["title"] end @@ -132,7 +132,7 @@ class ConditionalValidationTest < ActiveModel::TestCase assert t.valid?, "A topic with a basic title should be valid" t.title = "A very important title" - assert !t.valid?, "A topic with an important title, but without an author, should not be valid" + assert t.invalid?, "A topic with an important title, but without an author, should not be valid" assert t.errors[:author_name].any?, "A topic with an 'important' title should require an author" t.author_name = "Hubert J. Farnsworth" |