2017-05-22 13:00:07 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe ApplicationController do
|
2025-01-09 03:17:00 -05:00
|
|
|
render_views
|
|
|
|
|
|
2017-05-23 00:58:57 +09:00
|
|
|
controller do
|
2026-03-09 07:30:41 -04:00
|
|
|
def success = head(200)
|
2017-05-23 00:58:57 +09:00
|
|
|
end
|
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with a forgery' do
|
2026-03-09 07:30:41 -04:00
|
|
|
before do
|
2017-06-02 03:56:55 +09:00
|
|
|
ActionController::Base.allow_forgery_protection = true
|
|
|
|
|
routes.draw { post 'success' => 'anonymous#success' }
|
|
|
|
|
end
|
|
|
|
|
|
2026-03-09 07:30:41 -04:00
|
|
|
it 'responds with 422 and error page' do
|
|
|
|
|
post 'success'
|
|
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
|
.to have_http_status(422)
|
|
|
|
|
end
|
2017-06-02 03:56:55 +09:00
|
|
|
end
|
|
|
|
|
|
2017-05-23 00:58:57 +09:00
|
|
|
describe 'helper_method :current_account' do
|
|
|
|
|
it 'returns nil if not signed in' do
|
|
|
|
|
expect(controller.view_context.current_account).to be_nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns account if signed in' do
|
|
|
|
|
account = Fabricate(:account)
|
2022-01-28 00:46:42 +01:00
|
|
|
sign_in(account.user)
|
2017-05-23 00:58:57 +09:00
|
|
|
expect(controller.view_context.current_account).to eq account
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-22 13:00:07 +09:00
|
|
|
describe 'helper_method :single_user_mode?' do
|
|
|
|
|
it 'returns false if it is in single_user_mode but there is no account' do
|
|
|
|
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
2023-02-20 00:14:50 -05:00
|
|
|
expect(controller.view_context.single_user_mode?).to be false
|
2017-05-22 13:00:07 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns false if there is an account but it is not in single_user_mode' do
|
|
|
|
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
|
|
|
|
|
Fabricate(:account)
|
2023-02-20 00:14:50 -05:00
|
|
|
expect(controller.view_context.single_user_mode?).to be false
|
2017-05-22 13:00:07 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns true if it is in single_user_mode and there is an account' do
|
|
|
|
|
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
|
|
|
|
|
Fabricate(:account)
|
2023-02-20 00:14:50 -05:00
|
|
|
expect(controller.view_context.single_user_mode?).to be true
|
2017-05-22 13:00:07 +09:00
|
|
|
end
|
|
|
|
|
end
|
2017-05-23 00:58:57 +09:00
|
|
|
|
|
|
|
|
describe 'before_action :check_suspension' do
|
|
|
|
|
before do
|
|
|
|
|
routes.draw { get 'success' => 'anonymous#success' }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does nothing if not signed in' do
|
|
|
|
|
get 'success'
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2017-05-23 00:58:57 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does nothing if user who signed in is not suspended' do
|
2022-01-28 00:46:42 +01:00
|
|
|
sign_in(Fabricate(:account, suspended: false).user)
|
2017-05-23 00:58:57 +09:00
|
|
|
get 'success'
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2017-05-23 00:58:57 +09:00
|
|
|
end
|
|
|
|
|
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 10:48:50 +02:00
|
|
|
it 'redirects to account status page' do
|
2022-01-28 00:46:42 +01:00
|
|
|
sign_in(Fabricate(:account, suspended: true).user)
|
2017-05-23 00:58:57 +09:00
|
|
|
get 'success'
|
Change unconfirmed user login behaviour (#11375)
Allow access to account settings, 2FA, authorized applications, and
account deletions to unconfirmed and pending users, as well as
users who had their accounts disabled. Suspended users cannot update
their e-mail or password or delete their account.
Display account status on account settings page, for example, when
an account is frozen, limited, unconfirmed or pending review.
After sign up, login users straight away and show a simple page that
tells them the status of their account with links to account settings
and logout, to reduce onboarding friction and allow users to correct
wrongly typed e-mail addresses.
Move the final sign-up step of SSO integrations to be the same
as above to reduce code duplication.
2019-07-22 10:48:50 +02:00
|
|
|
expect(response).to redirect_to(edit_user_registration_path)
|
2017-05-23 00:58:57 +09:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'raise_not_found' do
|
|
|
|
|
it 'raises error' do
|
|
|
|
|
controller.params[:unmatched_route] = 'unmatched'
|
2018-10-04 20:36:53 +10:00
|
|
|
expect { controller.raise_not_found }.to raise_error(ActionController::RoutingError, 'No route matches unmatched')
|
2017-05-23 00:58:57 +09:00
|
|
|
end
|
|
|
|
|
end
|
2017-05-22 13:00:07 +09:00
|
|
|
end
|