From be69778d257ec424787d800c02c68ec7c7a0289d Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 5 Dec 2020 15:05:06 -0600 Subject: [PATCH] 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. --- app/logical/tag_mover.rb | 2 +- app/models/tag_implication.rb | 2 +- test/unit/bulk_update_request_test.rb | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/logical/tag_mover.rb b/app/logical/tag_mover.rb index 6c9c3a456..61c531353 100644 --- a/app/logical/tag_mover.rb +++ b/app/logical/tag_mover.rb @@ -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! diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index dff7f122f..2564e06f8 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -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 diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index c9661cf5d..96213ab08 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -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)