Gab Social. All are welcome.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountModerationNotesController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
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(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
|
||||
expect { subject }.not_to change { AccountModerationNote.count }
|
||||
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
|
||||
expect { subject }.to change { AccountModerationNote.count }.by(-1)
|
||||
expect(subject).to redirect_to admin_account_path(target_account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
239
spec/controllers/admin/accounts_controller_spec.rb
Normal file
239
spec/controllers/admin/accounts_controller_spec.rb
Normal file
@@ -0,0 +1,239 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountsController, type: :controller do
|
||||
render_views
|
||||
|
||||
before { sign_in current_user, scope: :user }
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:current_user) { Fabricate(:user, admin: true) }
|
||||
|
||||
around do |example|
|
||||
default_per_page = Account.default_per_page
|
||||
Account.paginates_per 1
|
||||
example.run
|
||||
Account.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'filters with parameters' do
|
||||
new = AccountFilter.method(:new)
|
||||
|
||||
expect(AccountFilter).to receive(:new) do |params|
|
||||
h = params.to_h
|
||||
|
||||
expect(h[:local]).to eq '1'
|
||||
expect(h[:remote]).to eq '1'
|
||||
expect(h[:by_domain]).to eq 'domain'
|
||||
expect(h[:active]).to eq '1'
|
||||
expect(h[:silenced]).to eq '1'
|
||||
expect(h[:suspended]).to eq '1'
|
||||
expect(h[:username]).to eq 'username'
|
||||
expect(h[:display_name]).to eq 'display name'
|
||||
expect(h[:email]).to eq 'local-part@domain'
|
||||
expect(h[:ip]).to eq '0.0.0.42'
|
||||
|
||||
new.call({})
|
||||
end
|
||||
|
||||
get :index, params: {
|
||||
local: '1',
|
||||
remote: '1',
|
||||
by_domain: 'domain',
|
||||
active: '1',
|
||||
silenced: '1',
|
||||
suspended: '1',
|
||||
username: 'username',
|
||||
display_name: 'display name',
|
||||
email: 'local-part@domain',
|
||||
ip: '0.0.0.42'
|
||||
}
|
||||
end
|
||||
|
||||
it 'paginates accounts' do
|
||||
Fabricate(:account)
|
||||
|
||||
get :index, params: { page: 2 }
|
||||
|
||||
accounts = assigns(:accounts)
|
||||
expect(accounts.count).to eq 1
|
||||
expect(accounts.klass).to be Account
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:current_user) { Fabricate(:user, admin: true) }
|
||||
let(:account) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: account.id }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #subscribe' do
|
||||
subject { post :subscribe, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: admin) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:admin) { true }
|
||||
|
||||
it { is_expected.to redirect_to admin_account_path(account.id) }
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:admin) { false }
|
||||
|
||||
it { is_expected.to have_http_status :forbidden }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unsubscribe' do
|
||||
subject { post :unsubscribe, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: admin) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:admin) { true }
|
||||
|
||||
it { is_expected.to redirect_to admin_account_path(account.id) }
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:admin) { false }
|
||||
|
||||
it { is_expected.to have_http_status :forbidden }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #memorialize' do
|
||||
subject { post :memorialize, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: current_user_admin) }
|
||||
let(:account) { Fabricate(:account, user: user) }
|
||||
let(:user) { Fabricate(:user, admin: target_user_admin) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:current_user_admin) { true }
|
||||
|
||||
context 'when target user is admin' do
|
||||
let(:target_user_admin) { true }
|
||||
|
||||
it 'fails to memorialize account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(account.reload).not_to be_memorial
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target user is not admin' do
|
||||
let(:target_user_admin) { false }
|
||||
|
||||
it 'succeeds in memorializing account' do
|
||||
is_expected.to redirect_to admin_account_path(account.id)
|
||||
expect(account.reload).to be_memorial
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:current_user_admin) { false }
|
||||
|
||||
context 'when target user is admin' do
|
||||
let(:target_user_admin) { true }
|
||||
|
||||
it 'fails to memorialize account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(account.reload).not_to be_memorial
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target user is not admin' do
|
||||
let(:target_user_admin) { false }
|
||||
|
||||
it 'fails to memorialize account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(account.reload).not_to be_memorial
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #enable' do
|
||||
subject { post :enable, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: admin) }
|
||||
let(:account) { Fabricate(:account, user: user) }
|
||||
let(:user) { Fabricate(:user, disabled: true) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:admin) { true }
|
||||
|
||||
it 'succeeds in enabling account' do
|
||||
is_expected.to redirect_to admin_account_path(account.id)
|
||||
expect(user.reload).not_to be_disabled
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:admin) { false }
|
||||
|
||||
it 'fails to enable account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(user.reload).to be_disabled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #redownload' do
|
||||
subject { post :redownload, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: admin) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:admin) { true }
|
||||
|
||||
it 'succeeds in redownloadin' do
|
||||
is_expected.to redirect_to admin_account_path(account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:admin) { false }
|
||||
|
||||
it 'fails to redownload' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #remove_avatar' do
|
||||
subject { post :remove_avatar, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: admin) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:admin) { true }
|
||||
|
||||
it 'succeeds in removing avatar' do
|
||||
is_expected.to redirect_to admin_account_path(account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:admin) { false }
|
||||
|
||||
it 'fails to remove avatar' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
14
spec/controllers/admin/action_logs_controller_spec.rb
Normal file
14
spec/controllers/admin/action_logs_controller_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ActionLogsController, type: :controller do
|
||||
describe 'GET #index' do
|
||||
it 'returns 200' do
|
||||
sign_in Fabricate(:user, admin: true)
|
||||
get :index, params: { page: 1 }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/controllers/admin/base_controller_spec.rb
Normal file
33
spec/controllers/admin/base_controller_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::BaseController, type: :controller do
|
||||
controller do
|
||||
def success
|
||||
render 'admin/reports/show'
|
||||
end
|
||||
end
|
||||
|
||||
it 'requires administrator or moderator' do
|
||||
routes.draw { get 'success' => 'admin/base#success' }
|
||||
sign_in(Fabricate(:user, admin: false, moderator: false))
|
||||
get :success
|
||||
|
||||
expect(response).to have_http_status(:forbidden)
|
||||
end
|
||||
|
||||
it 'renders admin layout as a moderator' do
|
||||
routes.draw { get 'success' => 'admin/base#success' }
|
||||
sign_in(Fabricate(:user, moderator: true))
|
||||
get :success
|
||||
expect(response).to render_template layout: 'admin'
|
||||
end
|
||||
|
||||
it 'renders admin layout as an admin' do
|
||||
routes.draw { get 'success' => 'admin/base#success' }
|
||||
sign_in(Fabricate(:user, admin: true))
|
||||
get :success
|
||||
expect(response).to render_template layout: 'admin'
|
||||
end
|
||||
end
|
||||
47
spec/controllers/admin/change_email_controller_spec.rb
Normal file
47
spec/controllers/admin/change_email_controller_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::ChangeEmailsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
account = Fabricate(:account)
|
||||
user = Fabricate(:user, account: account)
|
||||
|
||||
get :show, params: { account_id: account.id }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #update" do
|
||||
before do
|
||||
allow(UserMailer).to receive(:confirmation_instructions).and_return(double('email', deliver_later: nil))
|
||||
end
|
||||
|
||||
it "returns http success" do
|
||||
account = Fabricate(:account)
|
||||
user = Fabricate(:user, account: account)
|
||||
|
||||
previous_email = user.email
|
||||
|
||||
post :update, params: { account_id: account.id, user: { unconfirmed_email: 'test@example.com' } }
|
||||
|
||||
user.reload
|
||||
|
||||
expect(user.email).to eq previous_email
|
||||
expect(user.unconfirmed_email).to eq 'test@example.com'
|
||||
expect(user.confirmation_token).not_to be_nil
|
||||
|
||||
expect(UserMailer).to have_received(:confirmation_instructions).with(user, user.confirmation_token, { to: 'test@example.com' })
|
||||
|
||||
expect(response).to redirect_to(admin_account_path(account.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
64
spec/controllers/admin/confirmations_controller_spec.rb
Normal file
64
spec/controllers/admin/confirmations_controller_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::ConfirmationsController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'confirms the user' do
|
||||
account = Fabricate(:account)
|
||||
user = Fabricate(:user, confirmed_at: false, account: account)
|
||||
post :create, params: { account_id: account.id }
|
||||
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
expect(user.reload).to be_confirmed
|
||||
end
|
||||
|
||||
it 'raises an error when there is no account' do
|
||||
post :create, params: { account_id: 'fake' }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it 'raises an error when there is no user' do
|
||||
account = Fabricate(:account, user: nil)
|
||||
post :create, params: { account_id: account.id }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #resernd' do
|
||||
subject { post :resend, params: { account_id: account.id } }
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
let!(:user) { Fabricate(:user, confirmed_at: confirmed_at, account: account) }
|
||||
|
||||
before do
|
||||
allow(UserMailer).to receive(:confirmation_instructions) { double(:email, deliver_later: nil) }
|
||||
end
|
||||
|
||||
context 'when email is not confirmed' do
|
||||
let(:confirmed_at) { nil }
|
||||
|
||||
it 'resends confirmation mail' do
|
||||
expect(subject).to redirect_to admin_accounts_path
|
||||
expect(flash[:notice]).to eq I18n.t('admin.accounts.resend_confirmation.success')
|
||||
expect(UserMailer).to have_received(:confirmation_instructions).once
|
||||
end
|
||||
end
|
||||
|
||||
context 'when email is confirmed' do
|
||||
let(:confirmed_at) { Time.zone.now }
|
||||
|
||||
it 'does not resend confirmation mail' do
|
||||
expect(subject).to redirect_to admin_accounts_path
|
||||
expect(flash[:error]).to eq I18n.t('admin.accounts.resend_confirmation.already_confirmed')
|
||||
expect(UserMailer).not_to have_received(:confirmation_instructions)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
115
spec/controllers/admin/custom_emojis_controller_spec.rb
Normal file
115
spec/controllers/admin/custom_emojis_controller_spec.rb
Normal file
@@ -0,0 +1,115 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::CustomEmojisController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index }
|
||||
|
||||
before do
|
||||
Fabricate(:custom_emoji)
|
||||
end
|
||||
|
||||
it 'renders index page' do
|
||||
expect(subject).to have_http_status 200
|
||||
expect(subject).to render_template :index
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
subject { get :new }
|
||||
|
||||
it 'renders new page' do
|
||||
expect(subject).to have_http_status 200
|
||||
expect(subject).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
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test') }
|
||||
let(:image) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png'), 'image/png') }
|
||||
|
||||
before do
|
||||
put :update, params: { id: custom_emoji.id, custom_emoji: params }
|
||||
end
|
||||
|
||||
context 'when parameter is valid' do
|
||||
let(:params) { { shortcode: 'updated', image: image } }
|
||||
|
||||
it 'succeeds in updating custom emoji' do
|
||||
expect(flash[:notice]).to eq I18n.t('admin.custom_emojis.updated_msg')
|
||||
expect(custom_emoji.reload).to have_attributes(shortcode: 'updated')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when parameter is invalid' do
|
||||
let(:params) { { shortcode: 'u', image: image } }
|
||||
|
||||
it 'fails to update custom emoji' do
|
||||
expect(flash[:alert]).to eq I18n.t('admin.custom_emojis.update_failed_msg')
|
||||
expect(custom_emoji.reload).to have_attributes(shortcode: 'test')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #copy' do
|
||||
subject { post :copy, params: { id: custom_emoji.id } }
|
||||
|
||||
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test') }
|
||||
|
||||
it 'copies custom emoji' do
|
||||
expect { subject }.to change { CustomEmoji.where(shortcode: 'test').count }.by(1)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.custom_emojis.copied_msg')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #enable' do
|
||||
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test', disabled: true) }
|
||||
|
||||
before { post :enable, params: { id: custom_emoji.id } }
|
||||
|
||||
it 'enables custom emoji' do
|
||||
expect(response).to redirect_to admin_custom_emojis_path
|
||||
expect(custom_emoji.reload).to have_attributes(disabled: false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #disable' do
|
||||
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: 'test', disabled: false) }
|
||||
|
||||
before { post :disable, params: { id: custom_emoji.id } }
|
||||
|
||||
it 'enables custom emoji' do
|
||||
expect(response).to redirect_to admin_custom_emojis_path
|
||||
expect(custom_emoji.reload).to have_attributes(disabled: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
14
spec/controllers/admin/dashboard_controller_spec.rb
Normal file
14
spec/controllers/admin/dashboard_controller_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::DashboardController, type: :controller do
|
||||
describe 'GET #index' do
|
||||
it 'returns 200' do
|
||||
sign_in Fabricate(:user, admin: true)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
73
spec/controllers/admin/domain_blocks_controller_spec.rb
Normal file
73
spec/controllers/admin/domain_blocks_controller_spec.rb
Normal file
@@ -0,0 +1,73 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'assigns a new domain block' do
|
||||
get :new
|
||||
|
||||
expect(assigns(:domain_block)).to be_instance_of(DomainBlock)
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
domain_block = Fabricate(:domain_block)
|
||||
get :show, params: { id: domain_block.id }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'blocks the domain when succeeded to save' do
|
||||
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
|
||||
|
||||
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
|
||||
|
||||
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
|
||||
expect(response).to redirect_to(admin_instances_path(limited: '1'))
|
||||
end
|
||||
|
||||
it 'renders new when failed to save' do
|
||||
Fabricate(:domain_block, domain: 'example.com', severity: 'suspend')
|
||||
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
|
||||
|
||||
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
|
||||
|
||||
expect(DomainBlockWorker).not_to have_received(:perform_async)
|
||||
expect(response).to render_template :new
|
||||
end
|
||||
|
||||
it 'allows upgrading a block' do
|
||||
Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
||||
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
|
||||
|
||||
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence', reject_media: true, reject_reports: true } }
|
||||
|
||||
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
|
||||
expect(response).to redirect_to(admin_instances_path(limited: '1'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'unblocks the domain' do
|
||||
service = double(call: true)
|
||||
allow(UnblockDomainService).to receive(:new).and_return(service)
|
||||
domain_block = Fabricate(:domain_block)
|
||||
delete :destroy, params: { id: domain_block.id }
|
||||
|
||||
expect(service).to have_received(:call).with(domain_block)
|
||||
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.destroyed_msg')
|
||||
expect(response).to redirect_to(admin_instances_path(limited: '1'))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::EmailDomainBlocksController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = EmailDomainBlock.default_per_page
|
||||
EmailDomainBlock.paginates_per 1
|
||||
example.run
|
||||
EmailDomainBlock.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'renders email blacks' do
|
||||
2.times { Fabricate(:email_domain_block) }
|
||||
|
||||
get :index, params: { page: 2 }
|
||||
|
||||
assigned = assigns(:email_domain_blocks)
|
||||
expect(assigned.count).to eq 1
|
||||
expect(assigned.klass).to be EmailDomainBlock
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'assigns a new email black' do
|
||||
get :new
|
||||
|
||||
expect(assigns(:email_domain_block)).to be_instance_of(EmailDomainBlock)
|
||||
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: { email_domain_block: { domain: 'example.com' } }
|
||||
|
||||
expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg')
|
||||
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'unblocks the domain' do
|
||||
email_domain_block = Fabricate(:email_domain_block)
|
||||
delete :destroy, params: { id: email_domain_block.id }
|
||||
|
||||
expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg')
|
||||
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
32
spec/controllers/admin/instances_controller_spec.rb
Normal file
32
spec/controllers/admin/instances_controller_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::InstancesController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = Account.default_per_page
|
||||
Account.paginates_per 1
|
||||
example.run
|
||||
Account.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'renders instances' do
|
||||
Fabricate(:account, domain: 'popular')
|
||||
Fabricate(:account, domain: 'popular')
|
||||
Fabricate(:account, domain: 'less.popular')
|
||||
|
||||
get :index, params: { page: 2 }
|
||||
|
||||
instances = assigns(:instances).to_a
|
||||
expect(instances.size).to eq 1
|
||||
expect(instances[0].domain).to eq 'less.popular'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
59
spec/controllers/admin/invites_controller_spec.rb
Normal file
59
spec/controllers/admin/invites_controller_spec.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::InvitesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index, params: { available: true } }
|
||||
|
||||
let!(:invite) { Fabricate(:invite) }
|
||||
|
||||
it 'renders index page' do
|
||||
expect(subject).to render_template :index
|
||||
expect(assigns(:invites)).to include invite
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
|
||||
|
||||
it 'succeeds to create a invite' do
|
||||
expect { subject }.to change { Invite.count }.by(1)
|
||||
expect(subject).to redirect_to admin_invites_path
|
||||
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let!(:invite) { Fabricate(:invite, expires_at: nil) }
|
||||
|
||||
subject { delete :destroy, params: { id: invite.id } }
|
||||
|
||||
it 'expires invite' do
|
||||
expect(subject).to redirect_to admin_invites_path
|
||||
expect(invite.reload).to be_expired
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #deactivate_all' do
|
||||
it 'expires all invites, then redirects to admin_invites_path' do
|
||||
invites = Fabricate.times(2, :invite, expires_at: nil)
|
||||
|
||||
post :deactivate_all
|
||||
|
||||
invites.each do |invite|
|
||||
expect(invite.reload).to be_expired
|
||||
end
|
||||
|
||||
expect(response).to redirect_to admin_invites_path
|
||||
end
|
||||
end
|
||||
end
|
||||
90
spec/controllers/admin/report_notes_controller_spec.rb
Normal file
90
spec/controllers/admin/report_notes_controller_spec.rb
Normal file
@@ -0,0 +1,90 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ReportNotesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: params }
|
||||
|
||||
let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) }
|
||||
|
||||
context 'when parameter is valid' do
|
||||
context 'when report is unsolved' do
|
||||
let(:action_taken) { false }
|
||||
let(:account_id) { nil }
|
||||
|
||||
context 'when create_and_resolve flag is on' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
|
||||
|
||||
it 'creates a report note and resolves report' do
|
||||
expect { subject }.to change { ReportNote.count }.by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(subject).to redirect_to admin_reports_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_resolve flag is false' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||
|
||||
it 'creates a report note and does not resolve report' do
|
||||
expect { subject }.to change { ReportNote.count }.by(1)
|
||||
expect(report.reload).not_to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when report is resolved' do
|
||||
let(:action_taken) { true }
|
||||
let(:account_id) { user.account.id }
|
||||
|
||||
context 'when create_and_unresolve flag is on' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
|
||||
|
||||
it 'creates a report note and unresolves report' do
|
||||
expect { subject }.to change { ReportNote.count }.by(1)
|
||||
expect(report.reload).not_to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_unresolve flag is false' do
|
||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||
|
||||
it 'creates a report note and does not unresolve report' do
|
||||
expect { subject }.to change { ReportNote.count }.by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(subject).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when parameter is invalid' do
|
||||
let(:params) { { report_note: { content: '', report_id: report.id } } }
|
||||
let(:action_taken) { false }
|
||||
let(:account_id) { nil }
|
||||
|
||||
it 'renders admin/reports/show' do
|
||||
expect(subject).to render_template 'admin/reports/show'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
subject { delete :destroy, params: { id: report_note.id } }
|
||||
|
||||
let!(:report_note) { Fabricate(:report_note) }
|
||||
|
||||
it 'deletes note' do
|
||||
expect { subject }.to change { ReportNote.count }.by(-1)
|
||||
expect(subject).to redirect_to admin_report_path(report_note.report)
|
||||
end
|
||||
end
|
||||
end
|
||||
59
spec/controllers/admin/reported_statuses_controller_spec.rb
Normal file
59
spec/controllers/admin/reported_statuses_controller_spec.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ReportedStatusesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
let(:report) { Fabricate(:report, status_ids: [status.id]) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject do
|
||||
-> { post :create, params: { :report_id => report, action => '', :form_status_batch => { status_ids: status_ids } } }
|
||||
end
|
||||
|
||||
let(:action) { 'nsfw_on' }
|
||||
let(:status_ids) { [status.id] }
|
||||
let(:status) { Fabricate(:status, sensitive: !sensitive) }
|
||||
let(:sensitive) { true }
|
||||
let!(:media_attachment) { Fabricate(:media_attachment, status: status) }
|
||||
|
||||
context 'when action is nsfw_on' do
|
||||
it 'updates sensitive column' do
|
||||
is_expected.to change {
|
||||
status.reload.sensitive
|
||||
}.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when action is nsfw_off' do
|
||||
let(:action) { 'nsfw_off' }
|
||||
let(:sensitive) { false }
|
||||
|
||||
it 'updates sensitive column' do
|
||||
is_expected.to change {
|
||||
status.reload.sensitive
|
||||
}.from(true).to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when action is delete' do
|
||||
let(:action) { 'delete' }
|
||||
|
||||
it 'removes a status' do
|
||||
allow(RemovalWorker).to receive(:perform_async)
|
||||
subject.call
|
||||
expect(RemovalWorker).to have_received(:perform_async).with(status_ids.first)
|
||||
end
|
||||
end
|
||||
|
||||
it 'redirects to report page' do
|
||||
subject.call
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
end
|
||||
end
|
||||
end
|
||||
82
spec/controllers/admin/reports_controller_spec.rb
Normal file
82
spec/controllers/admin/reports_controller_spec.rb
Normal file
@@ -0,0 +1,82 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ReportsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success with no filters' do
|
||||
specified = Fabricate(:report, action_taken: false)
|
||||
Fabricate(:report, action_taken: true)
|
||||
|
||||
get :index
|
||||
|
||||
reports = assigns(:reports).to_a
|
||||
expect(reports.size).to eq 1
|
||||
expect(reports[0]).to eq specified
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns http success with resolved filter' do
|
||||
specified = Fabricate(:report, action_taken: true)
|
||||
Fabricate(:report, action_taken: false)
|
||||
|
||||
get :index, params: { resolved: 1 }
|
||||
|
||||
reports = assigns(:reports).to_a
|
||||
expect(reports.size).to eq 1
|
||||
expect(reports[0]).to eq specified
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'renders report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
get :show, params: { id: report }
|
||||
|
||||
expect(assigns(:report)).to eq report
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #reopen' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :reopen, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.action_taken_by_account).to eq nil
|
||||
expect(report.action_taken).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #assign_to_self' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :assign_to_self, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq user.account
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unassign' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :unassign, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
22
spec/controllers/admin/resets_controller_spec.rb
Normal file
22
spec/controllers/admin/resets_controller_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::ResetsController do
|
||||
render_views
|
||||
|
||||
let(:account) { Fabricate(:account, user: Fabricate(:user)) }
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'redirects to admin accounts page' do
|
||||
expect_any_instance_of(User).to receive(:send_reset_password_instructions) do |value|
|
||||
expect(value.account_id).to eq account.id
|
||||
end
|
||||
|
||||
post :create, params: { account_id: account.id }
|
||||
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/controllers/admin/roles_controller_spec.rb
Normal file
33
spec/controllers/admin/roles_controller_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::RolesController do
|
||||
render_views
|
||||
|
||||
let(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
sign_in admin, scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #promote' do
|
||||
subject { post :promote, params: { account_id: user.account_id } }
|
||||
|
||||
let(:user) { Fabricate(:user, moderator: false, admin: false) }
|
||||
|
||||
it 'promotes user' do
|
||||
expect(subject).to redirect_to admin_account_path(user.account_id)
|
||||
expect(user.reload).to be_moderator
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #demote' do
|
||||
subject { post :demote, params: { account_id: user.account_id } }
|
||||
|
||||
let(:user) { Fabricate(:user, moderator: true, admin: false) }
|
||||
|
||||
it 'demotes user' do
|
||||
expect(subject).to redirect_to admin_account_path(user.account_id)
|
||||
expect(user.reload).not_to be_moderator
|
||||
end
|
||||
end
|
||||
end
|
||||
71
spec/controllers/admin/settings_controller_spec.rb
Normal file
71
spec/controllers/admin/settings_controller_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::SettingsController, type: :controller do
|
||||
render_views
|
||||
|
||||
describe 'When signed in as an admin' do
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
it 'returns http success' do
|
||||
get :edit
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
before do
|
||||
allow_any_instance_of(Form::AdminSettings).to receive(:valid?).and_return(true)
|
||||
end
|
||||
|
||||
describe 'for a record that doesnt exist' do
|
||||
around do |example|
|
||||
before = Setting.site_extended_description
|
||||
Setting.site_extended_description = nil
|
||||
example.run
|
||||
Setting.site_extended_description = before
|
||||
Setting.new_setting_key = nil
|
||||
end
|
||||
|
||||
it 'cannot create a setting value for a non-admin key' do
|
||||
expect(Setting.new_setting_key).to be_blank
|
||||
|
||||
patch :update, params: { form_admin_settings: { new_setting_key: 'New key value' } }
|
||||
|
||||
expect(response).to redirect_to(edit_admin_settings_path)
|
||||
expect(Setting.new_setting_key).to be_nil
|
||||
end
|
||||
|
||||
it 'creates a settings value that didnt exist before for eligible key' do
|
||||
expect(Setting.site_extended_description).to be_blank
|
||||
|
||||
patch :update, params: { form_admin_settings: { site_extended_description: 'New key value' } }
|
||||
|
||||
expect(response).to redirect_to(edit_admin_settings_path)
|
||||
expect(Setting.site_extended_description).to eq 'New key value'
|
||||
end
|
||||
end
|
||||
|
||||
context do
|
||||
around do |example|
|
||||
site_title = Setting.site_title
|
||||
example.run
|
||||
Setting.site_title = site_title
|
||||
end
|
||||
|
||||
it 'updates a settings value' do
|
||||
Setting.site_title = 'Original'
|
||||
patch :update, params: { form_admin_settings: { site_title: 'New title' } }
|
||||
|
||||
expect(response).to redirect_to(edit_admin_settings_path)
|
||||
expect(Setting.site_title).to eq 'New title'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
77
spec/controllers/admin/statuses_controller_spec.rb
Normal file
77
spec/controllers/admin/statuses_controller_spec.rb
Normal file
@@ -0,0 +1,77 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::StatusesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, admin: true) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let!(:status) { Fabricate(:status, account: account) }
|
||||
let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
|
||||
let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) }
|
||||
let(:sensitive) { true }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success with no media' do
|
||||
get :index, params: { account_id: account.id }
|
||||
|
||||
statuses = assigns(:statuses).to_a
|
||||
expect(statuses.size).to eq 2
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns http success with media' do
|
||||
get :index, params: { account_id: account.id, media: true }
|
||||
|
||||
statuses = assigns(:statuses).to_a
|
||||
expect(statuses.size).to eq 1
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject do
|
||||
-> { post :create, params: { :account_id => account.id, action => '', :form_status_batch => { status_ids: status_ids } } }
|
||||
end
|
||||
|
||||
let(:action) { 'nsfw_on' }
|
||||
let(:status_ids) { [media_attached_status.id] }
|
||||
|
||||
context 'when action is nsfw_on' do
|
||||
it 'updates sensitive column' do
|
||||
is_expected.to change {
|
||||
media_attached_status.reload.sensitive
|
||||
}.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when action is nsfw_off' do
|
||||
let(:action) { 'nsfw_off' }
|
||||
let(:sensitive) { false }
|
||||
|
||||
it 'updates sensitive column' do
|
||||
is_expected.to change {
|
||||
media_attached_status.reload.sensitive
|
||||
}.from(true).to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when action is delete' do
|
||||
let(:action) { 'delete' }
|
||||
|
||||
it 'removes a status' do
|
||||
allow(RemovalWorker).to receive(:perform_async)
|
||||
subject.call
|
||||
expect(RemovalWorker).to have_received(:perform_async).with(status_ids.first)
|
||||
end
|
||||
end
|
||||
|
||||
it 'redirects to account statuses page' do
|
||||
subject.call
|
||||
expect(response).to redirect_to(admin_account_statuses_path(account.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
32
spec/controllers/admin/subscriptions_controller_spec.rb
Normal file
32
spec/controllers/admin/subscriptions_controller_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::SubscriptionsController, type: :controller do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = Subscription.default_per_page
|
||||
Subscription.paginates_per 1
|
||||
example.run
|
||||
Subscription.paginates_per default_per_page
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
it 'renders subscriptions' do
|
||||
Fabricate(:subscription)
|
||||
specified = Fabricate(:subscription)
|
||||
|
||||
get :index
|
||||
|
||||
subscriptions = assigns(:subscriptions)
|
||||
expect(subscriptions.count).to eq 1
|
||||
expect(subscriptions[0]).to eq specified
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
71
spec/controllers/admin/tags_controller_spec.rb
Normal file
71
spec/controllers/admin/tags_controller_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::TagsController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
account_tag_stat = Fabricate(:tag).account_tag_stat
|
||||
account_tag_stat.update(hidden: hidden, accounts_count: 1)
|
||||
get :index, params: { hidden: hidden }
|
||||
end
|
||||
|
||||
context 'with hidden tags' do
|
||||
let(:hidden) { true }
|
||||
|
||||
it 'returns status 200' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'without hidden tags' do
|
||||
let(:hidden) { false }
|
||||
|
||||
it 'returns status 200' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #hide' do
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
tag.account_tag_stat.update(hidden: false)
|
||||
post :hide, params: { id: tag.id }
|
||||
end
|
||||
|
||||
it 'hides tag' do
|
||||
tag.reload
|
||||
expect(tag).to be_hidden
|
||||
end
|
||||
|
||||
it 'redirects to admin_tags_path' do
|
||||
expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params)))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unhide' do
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
tag.account_tag_stat.update(hidden: true)
|
||||
post :unhide, params: { id: tag.id }
|
||||
end
|
||||
|
||||
it 'unhides tag' do
|
||||
tag.reload
|
||||
expect(tag).not_to be_hidden
|
||||
end
|
||||
|
||||
it 'redirects to admin_tags_path' do
|
||||
expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params)))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::TwoFactorAuthenticationsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, otp_required_for_login: true) }
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'redirects to admin accounts page' do
|
||||
delete :destroy, params: { user_id: user.id }
|
||||
|
||||
user.reload
|
||||
expect(user.otp_required_for_login).to eq false
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user