2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Admin::SpamLogsController do
|
2016-04-02 18:10:28 +05:30
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:first_spam) { create(:spam_log, user: user) }
|
|
|
|
let!(:second_spam) { create(:spam_log, user: user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
it 'lists all spam logs' do
|
|
|
|
get :index
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'removes only the spam log when removing log' do
|
2019-02-15 15:39:39 +05:30
|
|
|
expect { delete :destroy, params: { id: first_spam.id } }.to change { SpamLog.count }.by(-1)
|
2016-04-02 18:10:28 +05:30
|
|
|
expect(User.find(user.id)).to be_truthy
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user_destroy_with_limited_execution_time_worker is enabled' do
|
|
|
|
it 'initiates user removal', :sidekiq_inline do
|
|
|
|
expect do
|
|
|
|
delete :destroy, params: { id: first_spam.id, remove_user: true }
|
|
|
|
end.not_to change { SpamLog.count }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(
|
|
|
|
Users::GhostUserMigration.where(user: user,
|
|
|
|
initiator_user: admin)
|
|
|
|
).to be_exists
|
|
|
|
expect(flash[:notice]).to eq("User #{user.username} was successfully removed.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user_destroy_with_limited_execution_time_worker is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(user_destroy_with_limited_execution_time_worker: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes user and their spam logs when removing the user', :sidekiq_inline do
|
|
|
|
delete :destroy, params: { id: first_spam.id, remove_user: true }
|
|
|
|
|
|
|
|
expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(SpamLog.count).to eq(0)
|
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
describe '#mark_as_ham' do
|
|
|
|
before do
|
2020-03-13 15:44:24 +05:30
|
|
|
allow_next_instance_of(Spam::AkismetService) do |instance|
|
2019-12-26 22:10:19 +05:30
|
|
|
allow(instance).to receive(:submit_ham).and_return(true)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
it 'submits the log as ham' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post :mark_as_ham, params: { id: first_spam.id }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|