2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-07 19:26:43 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 04:49:53 +01:00
|
|
|
RSpec.describe Admin::AccountModerationNotesController do
|
2018-05-17 03:26:51 +01:00
|
|
|
render_views
|
|
|
|
|
2022-07-05 01:41:40 +01:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2018-05-17 03:26:51 +01:00
|
|
|
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
|
2023-05-24 10:23:40 +01:00
|
|
|
expect { subject }.to change(AccountModerationNote, :count).by(1)
|
2023-12-01 10:38:15 +00:00
|
|
|
expect(response).to redirect_to admin_account_path(target_account.id)
|
2018-05-17 03:26:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-15 14:38:36 +01:00
|
|
|
context 'when the content is too short' do
|
2018-05-17 03:26:51 +01:00
|
|
|
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
|
|
|
|
|
2024-05-15 14:38:36 +01:00
|
|
|
it 'fails to create a note' do
|
|
|
|
expect { subject }.to_not change(AccountModerationNote, :count)
|
|
|
|
expect(response).to render_template 'admin/accounts/show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the content is too long' do
|
|
|
|
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test' * AccountModerationNote::CONTENT_SIZE_LIMIT } } }
|
|
|
|
|
|
|
|
it 'fails to create a note' do
|
2023-05-24 10:23:40 +01:00
|
|
|
expect { subject }.to_not change(AccountModerationNote, :count)
|
2023-12-01 10:38:15 +00:00
|
|
|
expect(response).to render_template 'admin/accounts/show'
|
2018-05-17 03:26:51 +01:00
|
|
|
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
|
2023-05-24 10:23:40 +01:00
|
|
|
expect { subject }.to change(AccountModerationNote, :count).by(-1)
|
2023-12-01 10:38:15 +00:00
|
|
|
expect(response).to redirect_to admin_account_path(target_account.id)
|
2018-05-17 03:26:51 +01:00
|
|
|
end
|
|
|
|
end
|
2017-10-07 19:26:43 +01:00
|
|
|
end
|