BigW Consortium Gitlab

spam_logs_controller_spec.rb 1.03 KB
Newer Older
1 2 3
require 'spec_helper'

describe Admin::SpamLogsController do
4 5 6 7
  let(:admin) { create(:admin) }
  let(:user) { create(:user) }
  let!(:first_spam) { create(:spam_log, user: user) }
  let!(:second_spam) { create(:spam_log, user: user) }
8 9 10 11 12 13 14 15

  before do
    sign_in(admin)
  end

  describe '#index' do
    it 'lists all spam logs' do
      get :index
16

17 18 19 20 21
      expect(response.status).to eq(200)
    end
  end

  describe '#destroy' do
22
    it 'removes only the spam log when removing log' do
23
      expect { delete :destroy, id: first_spam.id }.to change { SpamLog.count }.by(-1)
24
      expect(User.find(user.id)).to be_truthy
25
      expect(response.status).to eq(200)
26 27
    end

28 29
    it 'removes user and his spam logs when removing the user' do
      delete :destroy, id: first_spam.id, remove_user: true
30

31
      expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
32
      expect(response.status).to eq(302)
33
      expect(SpamLog.count).to eq(0)
34 35 36 37
      expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
    end
  end
end