]> git.openstreetmap.org Git - rails.git/commitdiff
Rework 'empty' tag tests
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 23 Feb 2022 11:37:09 +0000 (11:37 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 30 Mar 2022 15:37:16 +0000 (16:37 +0100)
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
test/models/node_tag_test.rb
test/models/old_node_tag_test.rb
test/models/old_relation_tag_test.rb
test/models/old_way_tag_test.rb
test/models/relation_tag_test.rb
test/models/way_tag_test.rb

index 0c5ffb151cd69b4f4926867f1a4824f2d0fcd1a7..6846f90b455e73256c24b1908e386df564d18f1a 100644 (file)
@@ -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
 
index ffc8fb422d4655ac806a9ae861478c06bf35762a..a7e72df73ae4fa6bcc1c1e24b5389091b38ca564 100644 (file)
@@ -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
 
index ddcda22039d657316831f300d2b3a57e91d3b686..ed819c11165048d8ab388903b29a2f0af18fea14 100644 (file)
@@ -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
 
index a373e386df53bf839bed90ba965b6cd26221e133..d21cb27183d329e297a00e813cd4f01399d40119 100644 (file)
@@ -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
 
index 51c644c18f63b8592edadbe4d12d749b59ed78b9..121829111acf454d040f301959d4eb0ba667085a 100644 (file)
@@ -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
 
index 4e9108a634da14576367a047c8d6e57536c1e989..792671e2889296b1899229265bf699a863993cf0 100644 (file)
@@ -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
 
index cb225947c48ca554d8c78e0aa01c0359e1322d7a..da13068da4b5f6c0ef3a4b9091700b51eb8f7320 100644 (file)
@@ -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