2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-09 19:30:34 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::SpamLogsController do
|
2016-01-26 21:20:01 +00: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 19:30:34 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
it 'lists all spam logs' do
|
|
|
|
get :index
|
2016-01-26 21:20:01 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-01-09 19:30:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
2016-01-26 21:20:01 +00:00
|
|
|
it 'removes only the spam log when removing log' do
|
2018-12-17 22:52:17 +00:00
|
|
|
expect { delete :destroy, params: { id: first_spam.id } }.to change { SpamLog.count }.by(-1)
|
2016-01-09 19:30:34 +00:00
|
|
|
expect(User.find(user.id)).to be_truthy
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-01-09 19:30:34 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
it 'removes user and his spam logs when removing the user', :sidekiq_might_not_need_inline do
|
2018-12-17 22:52:17 +00:00
|
|
|
delete :destroy, params: { id: first_spam.id, remove_user: true }
|
2016-01-09 19:30:34 +00:00
|
|
|
|
2016-01-26 21:20:01 +00:00
|
|
|
expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-01-26 21:20:01 +00:00
|
|
|
expect(SpamLog.count).to eq(0)
|
2016-01-09 19:30:34 +00:00
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
2016-08-02 21:21:57 +00:00
|
|
|
|
|
|
|
describe '#mark_as_ham' do
|
|
|
|
before do
|
2019-11-14 03:06:25 +00:00
|
|
|
allow_next_instance_of(AkismetService) do |instance|
|
|
|
|
allow(instance).to receive(:submit_ham).and_return(true)
|
|
|
|
end
|
2016-08-02 21:21:57 +00:00
|
|
|
end
|
|
|
|
it 'submits the log as ham' do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :mark_as_ham, params: { id: first_spam.id }
|
2016-08-02 21:21:57 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-08-02 21:21:57 +00:00
|
|
|
expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-01-09 19:30:34 +00:00
|
|
|
end
|