]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3518'
authorTom Hughes <tom@compton.nu>
Wed, 30 Mar 2022 17:00:00 +0000 (18:00 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 30 Mar 2022 17:00:00 +0000 (18:00 +0100)
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..5832b8a706523674aeb96cc6ca21d8e770a9dcc8 100644 (file)
@@ -2,65 +2,45 @@ require "test_helper"
 
 class ChangesetTagTest < ActiveSupport::TestCase
   def test_length_key_valid
-    changeset = create(:changeset)
-
-    key = "k"
+    tag = create(:changeset_tag)
     [0, 255].each do |i|
-      tag = ChangesetTag.new
-      tag.changeset_id = changeset.id
-      tag.k = key * i
-      tag.v = "v"
+      tag.k = "k" * i
       assert_predicate tag, :valid?
     end
   end
 
   def test_length_value_valid
-    changeset = create(:changeset)
-
-    val = "v"
+    tag = create(:changeset_tag)
     [0, 255].each do |i|
-      tag = ChangesetTag.new
-      tag.changeset_id = changeset.id
-      tag.k = "k"
-      tag.v = val * i
+      tag.v = "v" * i
       assert_predicate tag, :valid?
     end
   end
 
   def test_length_key_invalid
-    ["k" * 256].each do |k|
-      tag = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = k
-      tag.v = "v"
-      assert_not tag.valid?, "Key #{k} should be too long"
-      assert_predicate tag.errors[:k], :any?
-    end
+    tag = create(:changeset_tag)
+    tag.k = "k" * 256
+    assert_not tag.valid?, "Key should be too long"
+    assert_predicate tag.errors[:k], :any?
   end
 
   def test_length_value_invalid
-    ["v" * 256].each do |v|
-      tag = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = "k"
-      tag.v = v
-      assert_not tag.valid?, "Value #{v} should be too long"
-      assert_predicate tag.errors[:v], :any?
-    end
+    tag = create(:changeset_tag)
+    tag.v = "v" * 256
+    assert_not tag.valid?, "Value should be too long"
+    assert_predicate tag.errors[:v], :any?
   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
 
   def test_uniqueness
     existing = create(:changeset_tag)
-    tag = ChangesetTag.new
-    tag.changeset_id = existing.changeset_id
-    tag.k = existing.k
-    tag.v = existing.v
+    tag = build(:changeset_tag, :changeset => existing.changeset, :k => existing.k, :v => existing.v)
     assert_predicate tag, :new_record?
     assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index ffc8fb422d4655ac806a9ae861478c06bf35762a..d927b5fea202edc7d9f945c40fa13bc2bdacbb0f 100644 (file)
@@ -31,18 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:node_tag)
-    tag = NodeTag.new
-    tag.node_id = existing.node_id
-    tag.k = existing.k
-    tag.v = existing.v
+    tag = build(:node_tag, :node => existing.node, :k => existing.k, :v => existing.v)
     assert_predicate tag, :new_record?
     assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index ddcda22039d657316831f300d2b3a57e91d3b686..40c91c82d54a9624f882cf1739623c4ca7a9d3ff 100644 (file)
@@ -31,19 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:old_node_tag)
-    tag = OldNodeTag.new
-    tag.node_id = existing.node_id
-    tag.version = existing.version
-    tag.k = existing.k
-    tag.v = existing.v
+    tag = build(:old_node_tag, :old_node => existing.old_node, :version => existing.version, :k => existing.k, :v => existing.v)
     assert_predicate tag, :new_record?
     assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index a373e386df53bf839bed90ba965b6cd26221e133..d920f91da197370f8225ece0c43b8778d222ff84 100644 (file)
@@ -31,19 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:old_relation_tag)
-    tag = OldRelationTag.new
-    tag.relation_id = existing.relation_id
-    tag.version = existing.version
-    tag.k = existing.k
-    tag.v = existing.v
+    tag = build(:old_relation_tag, :old_relation => existing.old_relation, :version => existing.version, :k => existing.k, :v => existing.v)
     assert_predicate tag, :new_record?
     assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index 51c644c18f63b8592edadbe4d12d749b59ed78b9..793962438dc57d49336b208b69af994ec3b8912d 100644 (file)
@@ -31,15 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:old_way_tag)
-    tag = OldWayTag.new
+    tag = build(:old_way_tag, :old_way => existing.old_way, :version => existing.version, :k => existing.k, :v => existing.v)
     tag.way_id = existing.way_id
     tag.version = existing.version
     tag.k = existing.k
index 4e9108a634da14576367a047c8d6e57536c1e989..69a491890101b0f8e5122198066f11300e2230e6 100644 (file)
@@ -31,18 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:relation_tag)
-    tag = RelationTag.new
-    tag.relation_id = existing.relation_id
-    tag.k = existing.k
-    tag.v = existing.v
+    tag = build(:relation_tag, :relation => existing.relation, :k => existing.k, :v => existing.v)
     assert_predicate tag, :new_record?
     assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index cb225947c48ca554d8c78e0aa01c0359e1322d7a..64aacc63b532660bb7278721addc0f8c9fc6001b 100644 (file)
@@ -31,15 +31,16 @@ 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
 
   def test_uniqueness
     existing = create(:way_tag)
-    tag = WayTag.new
+    tag = build(:way_tag, :way => existing.way, :k => existing.k, :v => existing.v)
     tag.way_id = existing.way_id
     tag.k = existing.k
     tag.v = existing.v