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

@@ -8,42 +8,13 @@ class TagBatchChangeJobTest < ActiveJob::TestCase
end
should "execute" do
TagBatchChangeJob.perform_now("aaa", "bbb", @user, "127.0.0.1")
TagBatchChangeJob.perform_now("aaa", "bbb")
assert_equal("bbb", @post.reload.tag_string)
end
should "move saved searches" do
ss = create(:saved_search, user: @user, query: "123 ... 456")
TagBatchChangeJob.perform_now("...", "bbb", @user, "127.0.0.1")
assert_equal("123 456 bbb", ss.reload.normalized_query)
end
should "move blacklists" do
@user.update(blacklisted_tags: "123 456\n789\n")
TagBatchChangeJob.perform_now("456", "xxx", @user, "127.0.0.1")
assert_equal("123 xxx\n789", @user.reload.blacklisted_tags)
end
should "move only saved searches that match the mass update exactly" do
ss = create(:saved_search, user: @user, query: "123 ... 456")
TagBatchChangeJob.perform_now("1", "bbb", @user, "127.0.0.1")
assert_equal("... 123 456", ss.reload.normalized_query, "expected '123' to remain unchanged")
TagBatchChangeJob.perform_now("123 456", "789", @user, "127.0.0.1")
assert_equal("... 789", ss.reload.normalized_query, "expected '123 456' to be changed to '789'")
end
should "log a modaction" do
TagBatchChangeJob.perform_now("1", "2", @user, "127.0.0.1")
TagBatchChangeJob.perform_now("1", "2")
assert_equal("mass_update", ModAction.last.category)
end
should "raise an error if there is no predicate" do
assert_raises(TagBatchChangeJob::Error) do
TagBatchChangeJob.perform_now("", "bbb", @user, "127.0.0.1")
end
end
end
end