account_moderation_notes_controller_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::AccountModerationNotesController, type: :controller do
  4. render_views
  5. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  6. let(:target_account) { Fabricate(:account) }
  7. before do
  8. sign_in user, scope: :user
  9. end
  10. describe 'POST #create' do
  11. subject { post :create, params: params }
  12. context 'when parameters are valid' do
  13. let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }
  14. it 'successfully creates a note' do
  15. expect { subject }.to change { AccountModerationNote.count }.by(1)
  16. expect(subject).to redirect_to admin_account_path(target_account.id)
  17. end
  18. end
  19. context 'when parameters are invalid' do
  20. let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
  21. it 'falls to create a note' do
  22. expect { subject }.to_not change { AccountModerationNote.count }
  23. expect(subject).to render_template 'admin/accounts/show'
  24. end
  25. end
  26. end
  27. describe 'DELETE #destroy' do
  28. subject { delete :destroy, params: { id: note.id } }
  29. let!(:note) { Fabricate(:account_moderation_note, account: account, target_account: target_account) }
  30. let(:account) { Fabricate(:account) }
  31. it 'destroys note' do
  32. expect { subject }.to change { AccountModerationNote.count }.by(-1)
  33. expect(subject).to redirect_to admin_account_path(target_account.id)
  34. end
  35. end
  36. end