You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

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