BURs: move cosplay tags when moving character tags.
When aliasing or renaming a character tag, move the corresponding *_(cosplay) tag if it exists.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user