Commit fd605619 authored by Stan Hu's avatar Stan Hu

Use DeleteUserWorker for removing users via spam logs

Before deleting a user via a SpamLog would just call `user.destroy`,
which may omit other things that need to be cleaned up.
parent dbcfbd68
No related merge requests found
...@@ -7,7 +7,7 @@ class Admin::SpamLogsController < Admin::ApplicationController ...@@ -7,7 +7,7 @@ class Admin::SpamLogsController < Admin::ApplicationController
spam_log = SpamLog.find(params[:id]) spam_log = SpamLog.find(params[:id])
if params[:remove_user] if params[:remove_user]
spam_log.remove_user spam_log.remove_user(deleted_by: current_user)
redirect_to admin_spam_logs_path, notice: "User #{spam_log.user.username} was successfully removed." redirect_to admin_spam_logs_path, notice: "User #{spam_log.user.username} was successfully removed."
else else
spam_log.destroy spam_log.destroy
......
...@@ -3,9 +3,9 @@ class SpamLog < ActiveRecord::Base ...@@ -3,9 +3,9 @@ class SpamLog < ActiveRecord::Base
validates :user, presence: true validates :user, presence: true
def remove_user def remove_user(deleted_by:)
user.block user.block
user.destroy DeleteUserWorker.perform_async(deleted_by.id, user.id, delete_solo_owned_groups: true, hard_delete: true)
end end
def text def text
......
require 'spec_helper' require 'spec_helper'
describe SpamLog, models: true do describe SpamLog, models: true do
let(:admin) { create(:admin) }
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
end end
...@@ -13,13 +15,18 @@ describe SpamLog, models: true do ...@@ -13,13 +15,18 @@ describe SpamLog, models: true do
it 'blocks the user' do it 'blocks the user' do
spam_log = build(:spam_log) spam_log = build(:spam_log)
expect { spam_log.remove_user }.to change { spam_log.user.blocked? }.to(true) expect { spam_log.remove_user(deleted_by: admin) }.to change { spam_log.user.blocked? }.to(true)
end end
it 'removes the user' do it 'removes the user' do
spam_log = build(:spam_log) spam_log = build(:spam_log)
user = spam_log.user
Sidekiq::Testing.inline! do
spam_log.remove_user(deleted_by: admin)
end
expect { spam_log.remove_user }.to change { User.count }.by(-1) expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment