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/with_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/with_validation_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/with_validation_test.rb | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb index 92df4dd6cd..b68b511852 100644 --- a/activemodel/test/cases/validations/with_validation_test.rb +++ b/activemodel/test/cases/validations/with_validation_test.rb @@ -4,7 +4,7 @@ require 'cases/tests_database' require 'models/topic' -class ValidatesWithTest < ActiveRecord::TestCase +class ValidatesWithTest < ActiveModel::TestCase include ActiveModel::TestsDatabase def teardown @@ -55,7 +55,7 @@ class ValidatesWithTest < ActiveRecord::TestCase test "vaidation with class that adds errors" do Topic.validates_with(ValidatorThatAddsErrors) topic = Topic.new - assert !topic.valid?, "A class that adds errors causes the record to be invalid" + assert topic.invalid?, "A class that adds errors causes the record to be invalid" assert topic.errors[:base].include?(ERROR_MESSAGE) end @@ -65,23 +65,10 @@ class ValidatesWithTest < ActiveRecord::TestCase assert topic.valid?, "A class that does not add errors does not cause the record to be invalid" end - test "with a class that adds errors on update and a new record" do - Topic.validates_with(ValidatorThatAddsErrors, :on => :update) - topic = Topic.new - assert topic.valid?, "Validation doesn't run on create if 'on' is set to update" - end - - test "with a class that adds errors on create and a new record" do - Topic.validates_with(ValidatorThatAddsErrors, :on => :create) - topic = Topic.new - assert !topic.valid?, "Validation does run on create if 'on' is set to create" - assert topic.errors[:base].include?(ERROR_MESSAGE) - end - test "with multiple classes" do Topic.validates_with(ValidatorThatAddsErrors, OtherValidatorThatAddsErrors) topic = Topic.new - assert !topic.valid? + assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) assert topic.errors[:base].include?(OTHER_ERROR_MESSAGE) end @@ -95,7 +82,7 @@ class ValidatesWithTest < ActiveRecord::TestCase test "with if statements that return true" do Topic.validates_with(ValidatorThatAddsErrors, :if => "1 == 1") topic = Topic.new - assert !topic.valid? + assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) end @@ -108,7 +95,7 @@ class ValidatesWithTest < ActiveRecord::TestCase test "with unless statements that returns false" do Topic.validates_with(ValidatorThatAddsErrors, :unless => "1 == 2") topic = Topic.new - assert !topic.valid? + assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) end @@ -121,7 +108,7 @@ class ValidatesWithTest < ActiveRecord::TestCase Topic.validates_with(validator, :if => "1 == 1", :foo => :bar) assert topic.valid? end - + test "calls setup method of validator passing in self when validator has setup method" do topic = Topic.new validator = stub_everything @@ -132,7 +119,7 @@ class ValidatesWithTest < ActiveRecord::TestCase Topic.validates_with(validator) assert topic.valid? end - + test "doesn't call setup method of validator when validator has no setup method" do topic = Topic.new validator = stub_everything @@ -147,14 +134,14 @@ class ValidatesWithTest < ActiveRecord::TestCase test "validates_with with options" do Topic.validates_with(ValidatorThatValidatesOptions, :field => :first_name) topic = Topic.new - assert !topic.valid? + assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) end test "validates_with each validator" do Topic.validates_with(ValidatorPerEachAttribute, :attributes => [:title, :content]) topic = Topic.new :title => "Title", :content => "Content" - assert !topic.valid? + assert topic.invalid? assert_equal ["Value is Title"], topic.errors[:title] assert_equal ["Value is Content"], topic.errors[:content] end @@ -174,7 +161,7 @@ class ValidatesWithTest < ActiveRecord::TestCase test "each validator skip nil values if :allow_nil is set to true" do Topic.validates_with(ValidatorPerEachAttribute, :attributes => [:title, :content], :allow_nil => true) topic = Topic.new :content => "" - assert !topic.valid? + assert topic.invalid? assert topic.errors[:title].empty? assert_equal ["Value is "], topic.errors[:content] end |