jobs: migrate mass updates to ActiveJob.

Also fixes a bug where mod actions weren't logged on mass updates.
Creating the mod action silently failed because it was called when
CurrentUser wasn' set.
This commit is contained in:
evazion
2019-08-19 00:46:31 -05:00
parent 48488d04db
commit dab43d96c9
7 changed files with 144 additions and 162 deletions

View File

@@ -1,77 +0,0 @@
require "test_helper"
module Moderator
class TagBatchChangeTest < ActiveSupport::TestCase
def setup
super
mock_saved_search_service!
end
context "a tag batch change" do
setup do
@user = FactoryBot.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryBot.create(:post, :tag_string => "aaa")
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "#estimate_update_count" do
setup do
@change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
end
should "find the correct count" do
assert_equal(1, @change.estimate_update_count)
end
end
should "execute" do
tag_batch_change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
tag_batch_change.perform
@post.reload
assert_equal("bbb", @post.tag_string)
end
should "move saved searches" do
ss = FactoryBot.create(:saved_search, :user => @user, :query => "123 ... 456")
tag_batch_change = TagBatchChange.new("...", "bbb", @user.id, "127.0.0.1")
tag_batch_change.perform
assert_equal("123 456 bbb", ss.reload.normalized_query)
end
should "move blacklists" do
@user.update(blacklisted_tags: "123 456\n789\n")
tag_batch_change = TagBatchChange.new("456", "xxx", @user.id, "127.0.0.1")
tag_batch_change.perform
@user.reload
assert_equal("123 xxx\n789", @user.blacklisted_tags)
end
should "move only saved searches that match the mass update exactly" do
ss = FactoryBot.create(:saved_search, :user => @user, :query => "123 ... 456")
tag_batch_change = TagBatchChange.new("1", "bbb", @user.id, "127.0.0.1")
tag_batch_change.perform
assert_equal("... 123 456", ss.reload.normalized_query, "expected '123' to remain unchanged")
tag_batch_change = TagBatchChange.new("123 456", "789", @user.id, "127.0.0.1")
tag_batch_change.perform
assert_equal("... 789", ss.reload.normalized_query, "expected '123 456' to be changed to '789'")
end
should "raise an error if there is no predicate" do
tag_batch_change = TagBatchChange.new("", "bbb", @user.id, "127.0.0.1")
assert_raises(TagBatchChange::Error) do
tag_batch_change.perform
end
end
end
end
end