From 374518f58ac5e598d669ffd4e7e3a945b68b877c Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 23 Feb 2022 11:37:09 +0000 Subject: [PATCH] Rework 'empty' tag tests These tests were checking that the parent object was set, but this was not obvious from the way that the tests were named and constructed. This refactoring makes it clearer what is being checked. --- test/models/changeset_tag_test.rb | 7 ++++--- test/models/node_tag_test.rb | 7 ++++--- test/models/old_node_tag_test.rb | 7 ++++--- test/models/old_relation_tag_test.rb | 7 ++++--- test/models/old_way_tag_test.rb | 7 ++++--- test/models/relation_tag_test.rb | 7 ++++--- test/models/way_tag_test.rb | 7 ++++--- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/test/models/changeset_tag_test.rb b/test/models/changeset_tag_test.rb index 0c5ffb151..6846f90b4 100644 --- a/test/models/changeset_tag_test.rb +++ b/test/models/changeset_tag_test.rb @@ -49,9 +49,10 @@ class ChangesetTagTest < ActiveSupport::TestCase end end - def test_empty_tag_invalid - tag = ChangesetTag.new - assert_not tag.valid?, "Empty tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:changeset_tag) + tag.changeset = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:changeset], :any? end diff --git a/test/models/node_tag_test.rb b/test/models/node_tag_test.rb index ffc8fb422..a7e72df73 100644 --- a/test/models/node_tag_test.rb +++ b/test/models/node_tag_test.rb @@ -31,9 +31,10 @@ class NodeTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_node_tag_invalid - tag = NodeTag.new - assert_not tag.valid?, "Empty tag should be invalid" + def test_orphaned_node_tag_invalid + tag = create(:node_tag) + tag.node = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:node], :any? end diff --git a/test/models/old_node_tag_test.rb b/test/models/old_node_tag_test.rb index ddcda2203..ed819c111 100644 --- a/test/models/old_node_tag_test.rb +++ b/test/models/old_node_tag_test.rb @@ -31,9 +31,10 @@ class OldNodeTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_tag_invalid - tag = OldNodeTag.new - assert_not tag.valid?, "Empty tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:old_node_tag) + tag.old_node = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:old_node], :any? end diff --git a/test/models/old_relation_tag_test.rb b/test/models/old_relation_tag_test.rb index a373e386d..d21cb2718 100644 --- a/test/models/old_relation_tag_test.rb +++ b/test/models/old_relation_tag_test.rb @@ -31,9 +31,10 @@ class OldRelationTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_tag_invalid - tag = OldRelationTag.new - assert_not tag.valid?, "Empty tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:old_relation_tag) + tag.old_relation = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:old_relation], :any? end diff --git a/test/models/old_way_tag_test.rb b/test/models/old_way_tag_test.rb index 51c644c18..121829111 100644 --- a/test/models/old_way_tag_test.rb +++ b/test/models/old_way_tag_test.rb @@ -31,9 +31,10 @@ class OldWayTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_tag_invalid - tag = OldWayTag.new - assert_not tag.valid?, "Empty tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:old_way_tag) + tag.old_way = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:old_way], :any? end diff --git a/test/models/relation_tag_test.rb b/test/models/relation_tag_test.rb index 4e9108a63..792671e28 100644 --- a/test/models/relation_tag_test.rb +++ b/test/models/relation_tag_test.rb @@ -31,9 +31,10 @@ class RelationTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_tag_invalid - tag = RelationTag.new - assert_not tag.valid?, "Empty relation tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:relation_tag) + tag.relation = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:relation], :any? end diff --git a/test/models/way_tag_test.rb b/test/models/way_tag_test.rb index cb225947c..da13068da 100644 --- a/test/models/way_tag_test.rb +++ b/test/models/way_tag_test.rb @@ -31,9 +31,10 @@ class WayTagTest < ActiveSupport::TestCase assert_predicate tag.errors[:v], :any? end - def test_empty_tag_invalid - tag = WayTag.new - assert_not tag.valid?, "Empty way tag should be invalid" + def test_orphaned_tag_invalid + tag = create(:way_tag) + tag.way = nil + assert_not tag.valid?, "Orphaned tag should be invalid" assert_predicate tag.errors[:way], :any? end -- 2.45.1