diff --git a/app/logical/tag_mover.rb b/app/logical/tag_mover.rb index 6bbd2bd86..8215e8baa 100644 --- a/app/logical/tag_mover.rb +++ b/app/logical/tag_mover.rb @@ -9,6 +9,7 @@ class TagMover def move! CurrentUser.scoped(user) do + move_cosplay_tag! move_tag_category! move_artist! move_wiki! @@ -56,6 +57,15 @@ class TagMover end end + def move_cosplay_tag! + old_cosplay_tag = "#{old_tag.name}_(cosplay)" + new_cosplay_tag = "#{new_tag.name}_(cosplay)" + + if Tag.nonempty.where(name: old_cosplay_tag).exists? + TagMover.new(old_cosplay_tag, new_cosplay_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 762f80444..da2e1221d 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -210,6 +210,21 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal(false, @bur.valid?) assert_equal(["Can't rename aaa -> bbb (the 'aaa' tag doesn't exist)"], @bur.errors.full_messages) end + + context "when renaming a character tag with a *_(cosplay) tag" do + should "move the *_(cosplay) tag as well" do + @post = create(:post, tag_string: "toosaka_rin_(cosplay)") + @wiki = create(:wiki_page, title: "toosaka_rin_(cosplay)") + @ta = create(:tag_alias, antecedent_name: "toosaka_rin", consequent_name: "tohsaka_rin") + + @bur = create(:bulk_update_request, script: "rename toosaka_rin -> tohsaka_rin") + @bur.approve!(@admin) + perform_enqueued_jobs + + assert_equal("cosplay tohsaka_rin tohsaka_rin_(cosplay)", @post.reload.tag_string) + assert_equal("tohsaka_rin_(cosplay)", @wiki.reload.title) + end + end end end