2023-02-22 02:55:31 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-07 21:26:43 +03:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 06:49:53 +03:00
|
|
|
RSpec.describe Admin::AccountModerationNotesController do
|
2018-05-17 05:26:51 +03:00
|
|
|
render_views
|
|
|
|
|
2022-07-05 03:41:40 +03:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2018-05-17 05:26:51 +03: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 12:23:40 +03:00
|
|
|
expect { subject }.to change(AccountModerationNote, :count).by(1)
|
2018-05-17 05:26:51 +03:00
|
|
|
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
|
2023-05-24 12:23:40 +03:00
|
|
|
expect { subject }.to_not change(AccountModerationNote, :count)
|
2018-05-17 05:26:51 +03:00
|
|
|
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
|
2023-05-24 12:23:40 +03:00
|
|
|
expect { subject }.to change(AccountModerationNote, :count).by(-1)
|
2018-05-17 05:26:51 +03:00
|
|
|
expect(subject).to redirect_to admin_account_path(target_account.id)
|
|
|
|
end
|
|
|
|
end
|
2017-10-07 21:26:43 +03:00
|
|
|
end
|