summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/spam_logs_controller_spec.rb
blob: 520a4f6f9c594f4a3197a59da40f247390cc52a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'spec_helper'

describe Admin::SpamLogsController do
  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

      expect(response).to have_http_status(200)
    end
  end

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

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

      expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
      expect(response).to have_http_status(302)
      expect(SpamLog.count).to eq(0)
      expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
    end
  end
end