BURs: fix validation error when aliasing tags with implications.

Bug: when aliasing a tag that implied another tag, it was possible for
the alias to fail. Moving the implication could fail because we checked
that the tag category of both tags in the implication was the same, but
we did this before the alias moved the category of the old tag to the
new tag.
This commit is contained in:
evazion
2020-12-05 15:05:06 -06:00
parent 9b48c98c61
commit be69778d25
3 changed files with 14 additions and 2 deletions

View File

@@ -9,10 +9,10 @@ class TagMover
def move!
CurrentUser.scoped(user) do
move_tag_category!
move_aliases!
move_implications!
move_cosplay_tag!
move_tag_category!
move_artist!
move_wiki!
move_saved_searches!

View File

@@ -11,7 +11,7 @@ class TagImplication < TagRelationship
validate :absence_of_transitive_relation
validate :antecedent_is_not_aliased
validate :consequent_is_not_aliased
validate :tag_categories_are_compatible
validate :tag_categories_are_compatible, on: :request
validate :meets_tag_size_requirements, on: :request
validate :has_wiki_page, on: :request

View File

@@ -82,6 +82,18 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal(true, TagImplication.where(antecedent_name: "ddd", consequent_name: "ccc", status: "active").exists?)
end
should "allow moving a copyright tag that implies another copyright tag" do
@t1 = create(:tag, name: "komeiji_koishi's_heart_throbbing_adventure", category: Tag.categories.general)
@t2 = create(:tag, name: "komeiji_koishi_no_dokidoki_daibouken", category: Tag.categories.copyright)
@t3 = create(:tag, name: "touhou", category: Tag.categories.copyright)
create(:tag_implication, antecedent_name: "komeiji_koishi_no_dokidoki_daibouken", consequent_name: "touhou")
create_bur!("alias komeiji_koishi_no_dokidoki_daibouken -> komeiji_koishi's_heart_throbbing_adventure", @admin)
assert_equal(true, @t1.reload.copyright?)
assert_equal(true, TagImplication.exists?(antecedent_name: "komeiji_koishi's_heart_throbbing_adventure", consequent_name: "touhou"))
end
should "allow aliases to be reversed in one step" do
@alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
@bur = create_bur!("create alias bbb -> aaa", @admin)