aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations/conditional_validation_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/test/cases/validations/conditional_validation_test.rb')
-rw-r--r--activemodel/test/cases/validations/conditional_validation_test.rb42
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"