BURs: make rename command move aliases/implications.

Make the tag rename command also move any aliases or implications from
the old tag to the new tag. Previously only the create alias command
moved aliases and implications.
This commit is contained in:
evazion
2020-11-12 17:12:09 -06:00
parent 9a287cd71f
commit 5844f16ed6
4 changed files with 50 additions and 52 deletions

View File

@@ -58,6 +58,38 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal("bar", @wiki.reload.title)
end
should "move any active aliases from the old tag to the new tag" do
@bur1 = create(:bulk_update_request, script: "alias aaa -> bbb")
@bur2 = create(:bulk_update_request, script: "alias bbb -> ccc")
@bur1.approve!(@admin)
@bur2.approve!(@admin)
perform_enqueued_jobs
assert_equal(false, TagAlias.where(antecedent_name: "aaa", consequent_name: "bbb", status: "active").exists?)
assert_equal(true, TagAlias.where(antecedent_name: "bbb", consequent_name: "ccc", status: "active").exists?)
assert_equal(true, TagAlias.where(antecedent_name: "aaa", consequent_name: "ccc", status: "active").exists?)
end
should "move any active implications from the old tag to the new tag" do
@bur1 = create(:bulk_update_request, script: "imply aaa -> bbb")
@bur2 = create(:bulk_update_request, script: "alias bbb -> ccc")
@bur1.approve!(@admin)
@bur2.approve!(@admin)
perform_enqueued_jobs
assert_equal(false, TagImplication.where(antecedent_name: "aaa", consequent_name: "bbb", status: "active").exists?)
assert_equal(true, TagImplication.where(antecedent_name: "aaa", consequent_name: "ccc", status: "active").exists?)
@bur3 = create(:bulk_update_request, script: "alias aaa -> ddd")
@bur3.approve!(@admin)
perform_enqueued_jobs
assert_equal(false, TagImplication.where(antecedent_name: "aaa", consequent_name: "ccc", status: "active").exists?)
assert_equal(true, TagImplication.where(antecedent_name: "ddd", consequent_name: "ccc", status: "active").exists?)
end
should "fail if the alias is invalid" do
create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
@bur = build(:bulk_update_request, script: "create alias bbb -> aaa")

View File

@@ -263,28 +263,6 @@ class TagAliasTest < ActiveSupport::TestCase
end
end
should "move existing aliases" do
ta1 = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :status => "pending")
ta2 = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc", :status => "pending")
# XXX this is broken, it depends on the order the jobs are executed in.
ta2.approve!(@admin)
ta1.approve!(@admin)
perform_enqueued_jobs
assert_equal("ccc", ta1.reload.consequent_name)
end
should "move existing implications" do
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ta = FactoryBot.create(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ccc")
ta.approve!(@admin)
perform_enqueued_jobs
assert_equal("ccc", ti.reload.consequent_name)
end
should "push the consequent's category to the antecedent if the antecedent is general" do
tag1 = create(:tag, name: "general", category: 0)
tag2 = create(:tag, name: "artist", category: 1)