about summary refs log tree commit diff
path: root/spec/controllers/admin/account_moderation_notes_controller_spec.rb
blob: d3f3263f884b812262c8aa08c6cc71fd916f5cdb (plain) (blame)
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
38
39
40
41
42
43
44
45
46
require 'rails_helper'

RSpec.describe Admin::AccountModerationNotesController, type: :controller do
  render_views

  let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  let(:target_account) { Fabricate(:account) }

  before do
    sign_in user, scope: :user
  end

  describe 'POST #create' do
    subject { post :create, params: params }

    context 'when parameters are valid' do
      let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }

      it 'successfully creates a note' do
        expect { subject }.to change { AccountModerationNote.count }.by(1)
        expect(subject).to redirect_to admin_account_path(target_account.id)
      end
    end

    context 'when parameters are invalid' do
      let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }

      it 'falls to create a note' do
        expect { subject }.not_to change { AccountModerationNote.count }
        expect(subject).to render_template 'admin/accounts/show'
      end
    end
  end

  describe 'DELETE #destroy' do
    subject { delete :destroy, params: { id: note.id } }

    let!(:note) { Fabricate(:account_moderation_note, account: account, target_account: target_account) }
    let(:account) { Fabricate(:account) }

    it 'destroys note' do
      expect { subject }.to change { AccountModerationNote.count }.by(-1)
      expect(subject).to redirect_to admin_account_path(target_account.id)
    end
  end
end