From b03d8e728d91d26f2a75b3ce9a265f30c5c5afd4 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 3 Feb 2021 21:27:35 -0600 Subject: [PATCH] Fix #4683: Automove _(style) tags when artists are processed via BUR. --- app/logical/tag_mover.rb | 10 ++++++++++ test/unit/bulk_update_request_test.rb | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/logical/tag_mover.rb b/app/logical/tag_mover.rb index 61c531353..b7cd41f42 100644 --- a/app/logical/tag_mover.rb +++ b/app/logical/tag_mover.rb @@ -13,6 +13,7 @@ class TagMover move_aliases! move_implications! move_cosplay_tag! + move_style_tag! move_artist! move_wiki! move_saved_searches! @@ -84,6 +85,15 @@ class TagMover end end + def move_style_tag! + old_style_tag = "#{old_tag.name}_(style)" + new_style_tag = "#{new_tag.name}_(style)" + + if old_tag.artist? && Tag.nonempty.exists?(name: old_style_tag) + TagMover.new(old_style_tag, new_style_tag).move! + end + end + def move_saved_searches! SavedSearch.rewrite_queries!(old_tag.name, new_tag.name) end diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 96213ab08..6a7e8664d 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -297,6 +297,19 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal("tohsaka_rin_(cosplay)", @wiki.reload.title) end end + + context "when renaming an artist tag with a *_(style) tag" do + should "move the *_(style) tag as well" do + create(:tag, name: "tanaka_takayuki", category: Tag.categories.artist) + @post = create(:post, tag_string: "tanaka_takayuki_(style)") + @wiki = create(:wiki_page, title: "tanaka_takayuki_(style)") + + create_bur!("rename tanaka_takayuki -> tony_taka", @admin) + + assert_equal("tony_taka_(style)", @post.reload.tag_string) + assert_equal("tony_taka_(style)", @wiki.reload.title) + end + end end context "the nuke command" do