Commit ec9f6180 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-use-delete-worker-spam-logs' into 'master'

Use DeleteUserWorker for removing users via spam logs

See merge request !10725
parents 2b934a7f fd605619
......@@ -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
......
......@@ -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
......
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
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
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