diff --git a/app/controllers/admin/spam_logs_controller.rb b/app/controllers/admin/spam_logs_controller.rb index 2abfa22712d..1d66955bb71 100644 --- a/app/controllers/admin/spam_logs_controller.rb +++ b/app/controllers/admin/spam_logs_controller.rb @@ -7,7 +7,7 @@ class Admin::SpamLogsController < Admin::ApplicationController spam_log = SpamLog.find(params[:id]) 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." else spam_log.destroy diff --git a/app/models/spam_log.rb b/app/models/spam_log.rb index 3b8b9833565..dd21ee15c6c 100644 --- a/app/models/spam_log.rb +++ b/app/models/spam_log.rb @@ -3,9 +3,9 @@ class SpamLog < ActiveRecord::Base validates :user, presence: true - def remove_user + def remove_user(deleted_by:) user.block - user.destroy + DeleteUserWorker.perform_async(deleted_by.id, user.id, delete_solo_owned_groups: true, hard_delete: true) end def text diff --git a/spec/models/spam_log_spec.rb b/spec/models/spam_log_spec.rb index c4ec7625cb0..838fba6c92d 100644 --- a/spec/models/spam_log_spec.rb +++ b/spec/models/spam_log_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe SpamLog, models: true do + let(:admin) { create(:admin) } + describe 'associations' do it { is_expected.to belong_to(:user) } end @@ -13,13 +15,18 @@ describe SpamLog, models: true do it 'blocks the user' do 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 it 'removes the user' do spam_log = build(:spam_log) + user = spam_log.user - expect { spam_log.remove_user }.to change { User.count }.by(-1) + Sidekiq::Testing.inline! do + spam_log.remove_user(deleted_by: admin) + end + + expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end