account_moderation_notes_controller_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::AccountModerationNotesController 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(response).to redirect_to admin_account_path(target_account.id)
  17. end
  18. end
  19. context 'when the content is too short' do
  20. let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
  21. it 'fails to create a note' do
  22. expect { subject }.to_not change(AccountModerationNote, :count)
  23. expect(response).to render_template 'admin/accounts/show'
  24. end
  25. end
  26. context 'when the content is too long' do
  27. let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test' * AccountModerationNote::CONTENT_SIZE_LIMIT } } }
  28. it 'fails to create a note' do
  29. expect { subject }.to_not change(AccountModerationNote, :count)
  30. expect(response).to render_template 'admin/accounts/show'
  31. end
  32. end
  33. end
  34. describe 'DELETE #destroy' do
  35. subject { delete :destroy, params: { id: note.id } }
  36. let!(:note) { Fabricate(:account_moderation_note, account: account, target_account: target_account) }
  37. let(:account) { Fabricate(:account) }
  38. it 'destroys note' do
  39. expect { subject }.to change(AccountModerationNote, :count).by(-1)
  40. expect(response).to redirect_to admin_account_path(target_account.id)
  41. end
  42. end
  43. end