spam_logs_controller_spec.rb 1.39 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
      expect(response).to have_http_status(200)
18 19 20 21
    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).to have_http_status(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).to have_http_status(302)
33
      expect(SpamLog.count).to eq(0)
34 35 36
      expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
    end
  end
37 38 39

  describe '#mark_as_ham' do
    before do
40
      allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
41 42 43 44 45 46 47 48
    end
    it 'submits the log as ham' do
      post :mark_as_ham, id: first_spam.id

      expect(response).to have_http_status(302)
      expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
    end
  end
49
end