From 5c2cb9e96fdc00c7efd72ba4186308127e45855c Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 30 Mar 2022 17:15:11 +0100 Subject: [PATCH] Use factories for tag uniqueness tests --- test/models/changeset_tag_test.rb | 5 +---- test/models/node_tag_test.rb | 5 +---- test/models/old_node_tag_test.rb | 6 +----- test/models/old_relation_tag_test.rb | 6 +----- test/models/old_way_tag_test.rb | 2 +- test/models/relation_tag_test.rb | 5 +---- test/models/way_tag_test.rb | 2 +- 7 files changed, 7 insertions(+), 24 deletions(-) diff --git a/test/models/changeset_tag_test.rb b/test/models/changeset_tag_test.rb index 4ac372416..5832b8a70 100644 --- a/test/models/changeset_tag_test.rb +++ b/test/models/changeset_tag_test.rb @@ -40,10 +40,7 @@ class ChangesetTagTest < ActiveSupport::TestCase 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! } diff --git a/test/models/node_tag_test.rb b/test/models/node_tag_test.rb index a7e72df73..d927b5fea 100644 --- a/test/models/node_tag_test.rb +++ b/test/models/node_tag_test.rb @@ -40,10 +40,7 @@ class NodeTagTest < ActiveSupport::TestCase 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! } diff --git a/test/models/old_node_tag_test.rb b/test/models/old_node_tag_test.rb index ed819c111..40c91c82d 100644 --- a/test/models/old_node_tag_test.rb +++ b/test/models/old_node_tag_test.rb @@ -40,11 +40,7 @@ class OldNodeTagTest < ActiveSupport::TestCase 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! } diff --git a/test/models/old_relation_tag_test.rb b/test/models/old_relation_tag_test.rb index d21cb2718..d920f91da 100644 --- a/test/models/old_relation_tag_test.rb +++ b/test/models/old_relation_tag_test.rb @@ -40,11 +40,7 @@ class OldRelationTagTest < ActiveSupport::TestCase 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! } diff --git a/test/models/old_way_tag_test.rb b/test/models/old_way_tag_test.rb index 121829111..793962438 100644 --- a/test/models/old_way_tag_test.rb +++ b/test/models/old_way_tag_test.rb @@ -40,7 +40,7 @@ class OldWayTagTest < ActiveSupport::TestCase 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 diff --git a/test/models/relation_tag_test.rb b/test/models/relation_tag_test.rb index 792671e28..69a491890 100644 --- a/test/models/relation_tag_test.rb +++ b/test/models/relation_tag_test.rb @@ -40,10 +40,7 @@ class RelationTagTest < ActiveSupport::TestCase 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! } diff --git a/test/models/way_tag_test.rb b/test/models/way_tag_test.rb index da13068da..64aacc63b 100644 --- a/test/models/way_tag_test.rb +++ b/test/models/way_tag_test.rb @@ -40,7 +40,7 @@ class WayTagTest < ActiveSupport::TestCase 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 -- 2.39.5