Fix #4491: Have tag rename option for bulk update requests.

* Add a `rename A -> B` command for bulk update requests.
* Change mass updates to only retag the posts, not to move saved
  searches or blacklists.

A tag rename does the same thing an alias does, except it doesn't
create a permanent alias. More precisely, a tag rename:

* Moves the wiki.
* Moves the artist entry.
* Moves saved searches.
* Moves blacklists.
* Merges the wikis, if both tags have wiki pages.
* Merges the artist entries, if both tags have artist pages.
* Fixes links in wiki pages to point to the new tag.
* Retags the posts.
This commit is contained in:
evazion
2020-08-26 19:25:14 -05:00
parent bbf2b53d83
commit 23944a1794
6 changed files with 61 additions and 92 deletions

View File

@@ -182,6 +182,35 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal("Imageboard", @post.reload.source)
end
end
context "the rename command" do
setup do
@artist = create(:artist, name: "foo")
@wiki = create(:wiki_page, title: "foo", body: "[[foo]]")
@post = create(:post, tag_string: "foo blah")
@bur = create(:bulk_update_request, script: "rename foo -> bar")
@bur.approve!(@admin)
perform_enqueued_jobs
end
should "rename the tags" do
assert_equal("approved", @bur.status)
assert_equal("bar blah", @post.reload.tag_string)
end
should "move the tag's artist entry and wiki page" do
assert_equal("bar", @artist.reload.name)
assert_equal("bar", @wiki.reload.title)
assert_equal("[[bar]]", @wiki.body)
end
should "fail if the old tag doesn't exist" do
@bur = build(:bulk_update_request, script: "rename aaa -> bbb")
assert_equal(false, @bur.valid?)
assert_equal(["Can't rename aaa -> bbb (the 'aaa' tag doesn't exist)"], @bur.errors.full_messages)
end
end
end
context "when validating a script" do