Merge remote-tracking branch 'parent/main' into upstream-20241231
This commit is contained in:
commit
3c77d4e8e4
268 changed files with 4213 additions and 3029 deletions
|
@ -1,57 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountModerationNotesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
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
|
||||
expect { subject }.to change(AccountModerationNote, :count).by(1)
|
||||
expect(response).to redirect_to admin_account_path(target_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the content is too short' do
|
||||
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
|
||||
|
||||
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
|
||||
expect { subject }.to_not change(AccountModerationNote, :count)
|
||||
expect(response).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
|
||||
expect { subject }.to change(AccountModerationNote, :count).by(-1)
|
||||
expect(response).to redirect_to admin_account_path(target_account.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::CustomEmojisController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
Fabricate(:custom_emoji)
|
||||
end
|
||||
|
||||
it 'renders index page' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status 200
|
||||
expect(response).to render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'renders new page' do
|
||||
get :new
|
||||
|
||||
expect(response).to have_http_status 200
|
||||
expect(response).to render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: { custom_emoji: params } }
|
||||
|
||||
let(:image) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png'), 'image/png') }
|
||||
|
||||
context 'when parameter is valid' do
|
||||
let(:params) { { shortcode: 'test', image: image } }
|
||||
|
||||
it 'creates custom emoji' do
|
||||
expect { subject }.to change(CustomEmoji, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when parameter is invalid' do
|
||||
let(:params) { { shortcode: 't', image: image } }
|
||||
|
||||
it 'renders new' do
|
||||
expect(subject).to render_template :new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::DomainAllowsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'assigns a new domain allow' do
|
||||
get :new
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'blocks the domain when succeeded to save' do
|
||||
post :create, params: { domain_allow: { domain: 'example.com' } }
|
||||
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_allows.created_msg')
|
||||
expect(response).to redirect_to(admin_instances_path)
|
||||
end
|
||||
|
||||
it 'renders new when failed to save' do
|
||||
Fabricate(:domain_allow, domain: 'example.com')
|
||||
|
||||
post :create, params: { domain_allow: { domain: 'example.com' } }
|
||||
|
||||
expect(response).to render_template :new
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'disallows the domain' do
|
||||
service = instance_double(UnallowDomainService, call: true)
|
||||
allow(UnallowDomainService).to receive(:new).and_return(service)
|
||||
domain_allow = Fabricate(:domain_allow)
|
||||
delete :destroy, params: { id: domain_allow.id }
|
||||
|
||||
expect(service).to have_received(:call).with(domain_allow)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_allows.destroyed_msg')
|
||||
expect(response).to redirect_to(admin_instances_path)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::IpBlocksController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'returns http success and renders view' do
|
||||
get :new
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with valid data' do
|
||||
it 'creates a new ip block and redirects' do
|
||||
expect do
|
||||
post :create, params: { ip_block: { ip: '1.1.1.1', severity: 'no_access', expires_in: 1.day.to_i.to_s } }
|
||||
end.to change(IpBlock, :count).by(1)
|
||||
|
||||
expect(response).to redirect_to(admin_ip_blocks_path)
|
||||
expect(flash.notice).to match(I18n.t('admin.ip_blocks.created_msg'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid data' do
|
||||
it 'does not create new a ip block and renders new' do
|
||||
expect do
|
||||
post :create, params: { ip_block: { ip: '1.1.1.1' } }
|
||||
end.to_not change(IpBlock, :count)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,117 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::WebhooksController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'returns http success and renders view' do
|
||||
get :new
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'creates a new webhook record with valid data' do
|
||||
expect do
|
||||
post :create, params: { webhook: { url: 'https://example.com/hook', events: ['account.approved'] } }
|
||||
end.to change(Webhook, :count).by(1)
|
||||
|
||||
expect(response).to be_redirect
|
||||
end
|
||||
|
||||
it 'does not create a new webhook record with invalid data' do
|
||||
expect do
|
||||
post :create, params: { webhook: { url: 'https://example.com/hook', events: [] } }
|
||||
end.to_not change(Webhook, :count)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an existing record' do
|
||||
let!(:webhook) { Fabricate(:webhook, events: ['account.created', 'report.created']) }
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success and renders view' do
|
||||
get :show, params: { id: webhook.id }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
it 'returns http success and renders view' do
|
||||
get :edit, params: { id: webhook.id }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
it 'updates the record with valid data' do
|
||||
put :update, params: { id: webhook.id, webhook: { url: 'https://example.com/new/location' } }
|
||||
|
||||
expect(webhook.reload.url).to match(%r{new/location})
|
||||
expect(response).to redirect_to(admin_webhook_path(webhook))
|
||||
end
|
||||
|
||||
it 'does not update the record with invalid data' do
|
||||
expect do
|
||||
put :update, params: { id: webhook.id, webhook: { url: '' } }
|
||||
end.to_not change(webhook, :url)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #enable' do
|
||||
it 'enables the webhook' do
|
||||
post :enable, params: { id: webhook.id }
|
||||
|
||||
expect(webhook.reload).to be_enabled
|
||||
expect(response).to redirect_to(admin_webhook_path(webhook))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #disable' do
|
||||
it 'disables the webhook' do
|
||||
post :disable, params: { id: webhook.id }
|
||||
|
||||
expect(webhook.reload).to_not be_enabled
|
||||
expect(response).to redirect_to(admin_webhook_path(webhook))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'destroys the record' do
|
||||
expect do
|
||||
delete :destroy, params: { id: webhook.id }
|
||||
end.to change(Webhook, :count).by(-1)
|
||||
|
||||
expect(response).to redirect_to(admin_webhooks_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue