Skip to content

Commit

Permalink
use assert_empty in activemodel conditional validation test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajarshi Das committed Sep 10, 2013
1 parent a1de8a8 commit 782d794
Showing 1 changed file with 7 additions and 7 deletions.
Expand Up @@ -23,15 +23,15 @@ def test_unless_validation_using_method_true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: :condition_is_true)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
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.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
end

def test_unless_validation_using_method_false
Expand All @@ -57,15 +57,15 @@ def test_unless_validation_using_string_true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: "a = 1; a == 1")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
end

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.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
end

def test_unless_validation_using_string_false
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_unless_validation_using_block_true
unless: Proc.new { |r| r.content.size > 4 })
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
end

def test_if_validation_using_block_false
Expand All @@ -102,7 +102,7 @@ def test_if_validation_using_block_false
if: Proc.new { |r| r.title != "uhohuhoh"})
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert t.errors[:title].empty?
assert_empty t.errors[:title]
end

def test_unless_validation_using_block_false
Expand All @@ -124,7 +124,7 @@ def test_validation_with_if_as_string

t = Topic.new
assert t.invalid?, "A topic without a title should not be valid"
assert t.errors[:author_name].empty?, "A topic without an 'important' title should not require an author"
assert_empty t.errors[:author_name], "A topic without an 'important' title should not require an author"

t.title = "Just a title"
assert t.valid?, "A topic with a basic title should be valid"
Expand Down

0 comments on commit 782d794

Please sign in to comment.