2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-09 14:30:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Admin::SpamLogsController do
|
2016-01-26 16:20:01 -05:00
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:first_spam) { create(:spam_log, user: user) }
|
|
|
|
let!(:second_spam) { create(:spam_log, user: user) }
|
2016-01-09 14:30:34 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
it 'lists all spam logs' do
|
|
|
|
get :index
|
2016-01-26 16:20:01 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
2016-01-26 16:20:01 -05:00
|
|
|
it 'removes only the spam log when removing log' do
|
2018-12-17 17:52:17 -05:00
|
|
|
expect { delete :destroy, params: { id: first_spam.id } }.to change { SpamLog.count }.by(-1)
|
2016-01-09 14:30:34 -05:00
|
|
|
expect(User.find(user.id)).to be_truthy
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
|
2020-02-07 04:08:49 -05:00
|
|
|
it 'removes user and their spam logs when removing the user', :sidekiq_might_not_need_inline do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: { id: first_spam.id, remove_user: true }
|
2016-01-09 14:30:34 -05:00
|
|
|
|
2016-01-26 16:20:01 -05:00
|
|
|
expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2016-01-26 16:20:01 -05:00
|
|
|
expect(SpamLog.count).to eq(0)
|
2016-01-09 14:30:34 -05:00
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
2016-08-02 17:21:57 -04:00
|
|
|
|
|
|
|
describe '#mark_as_ham' do
|
|
|
|
before do
|
2020-01-30 10:09:15 -05:00
|
|
|
allow_next_instance_of(Spam::AkismetService) do |instance|
|
2019-11-13 22:06:25 -05:00
|
|
|
allow(instance).to receive(:submit_ham).and_return(true)
|
|
|
|
end
|
2016-08-02 17:21:57 -04:00
|
|
|
end
|
|
|
|
it 'submits the log as ham' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :mark_as_ham, params: { id: first_spam.id }
|
2016-08-02 17:21:57 -04:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2016-08-02 17:21:57 -04:00
|
|
|
expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|