2016-01-09 14:30:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
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
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
|
2016-01-26 16:20:01 -05:00
|
|
|
it 'removes user and his spam logs when removing the user' 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."
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
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
|
2016-08-09 13:43:47 -04:00
|
|
|
allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
|
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
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
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
|