diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/controllers/registrations_controller_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/controllers/registrations_controller_spec.rb')
-rw-r--r-- | spec/controllers/registrations_controller_spec.rb | 198 |
1 files changed, 61 insertions, 137 deletions
diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 501d8d4a78d..2fb17e56f37 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -7,35 +7,16 @@ RSpec.describe RegistrationsController do before do stub_feature_flags(invisible_captcha: false) + stub_application_setting(require_admin_approval_after_user_signup: false) end describe '#new' do subject { get :new } - context 'with the experimental signup flow enabled and the user is part of the experimental group' do - before do - stub_experiment(signup_flow: true) - stub_experiment_for_user(signup_flow: true) - end - - it 'renders new template and sets the resource variable' do - expect(subject).to render_template(:new) - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:resource)).to be_a(User) - end - end - - context 'with the experimental signup flow enabled and the user is part of the control group' do - before do - stub_experiment(signup_flow: true) - stub_experiment_for_user(signup_flow: false) - end - - it 'renders new template and sets the resource variable' do - subject - expect(response).to have_gitlab_http_status(:found) - expect(response).to redirect_to(new_user_session_path(anchor: 'register-pane')) - end + it 'renders new template and sets the resource variable' do + expect(subject).to render_template(:new) + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:resource)).to be_a(User) end end @@ -46,102 +27,86 @@ RSpec.describe RegistrationsController do subject { post(:create, params: user_params) } context '`blocked_pending_approval` state' do - context 'when the feature is enabled' do + context 'when the `require_admin_approval_after_user_signup` setting is turned on' do before do - stub_feature_flags(admin_approval_for_new_user_signups: true) + stub_application_setting(require_admin_approval_after_user_signup: true) end - context 'when the `require_admin_approval_after_user_signup` setting is turned on' do - before do - stub_application_setting(require_admin_approval_after_user_signup: true) - end + it 'signs up the user in `blocked_pending_approval` state' do + subject + created_user = User.find_by(email: 'new@user.com') - it 'signs up the user in `blocked_pending_approval` state' do - subject - created_user = User.find_by(email: 'new@user.com') + expect(created_user).to be_present + expect(created_user.blocked_pending_approval?).to eq(true) + end - expect(created_user).to be_present - expect(created_user.blocked_pending_approval?).to eq(true) - end + it 'does not log in the user after sign up' do + subject - it 'does not log in the user after sign up' do - subject + expect(controller.current_user).to be_nil + end - expect(controller.current_user).to be_nil - end + it 'shows flash message after signing up' do + subject - it 'shows flash message after signing up' do - subject + expect(response).to redirect_to(new_user_session_path(anchor: 'login-pane')) + expect(flash[:notice]) + .to eq('You have signed up successfully. However, we could not sign you in because your account is awaiting approval from your GitLab administrator.') + end - expect(response).to redirect_to(new_user_session_path(anchor: 'login-pane')) - expect(flash[:notice]) - .to eq('You have signed up successfully. However, we could not sign you in because your account is awaiting approval from your GitLab administrator.') + it 'emails the access request to approvers' do + expect_next_instance_of(NotificationService) do |notification| + allow(notification).to receive(:new_instance_access_request).with(User.find_by(email: 'new@user.com')) end - context 'email confirmation' do - context 'when `send_user_confirmation_email` is true' do - before do - stub_application_setting(send_user_confirmation_email: true) - end - - it 'does not send a confirmation email' do - expect { subject } - .not_to have_enqueued_mail(DeviseMailer, :confirmation_instructions) - end - end - end + subject end - context 'when the `require_admin_approval_after_user_signup` setting is turned off' do - before do - stub_application_setting(require_admin_approval_after_user_signup: false) - end - - it 'signs up the user in `active` state' do - subject - created_user = User.find_by(email: 'new@user.com') + context 'email confirmation' do + context 'when `send_user_confirmation_email` is true' do + before do + stub_application_setting(send_user_confirmation_email: true) + end - expect(created_user).to be_present - expect(created_user.active?).to eq(true) + it 'does not send a confirmation email' do + expect { subject } + .not_to have_enqueued_mail(DeviseMailer, :confirmation_instructions) + end end + end + end - it 'does not show any flash message after signing up' do - subject + context 'when the `require_admin_approval_after_user_signup` setting is turned off' do + it 'signs up the user in `active` state' do + subject + created_user = User.find_by(email: 'new@user.com') - expect(flash[:notice]).to be_nil - end + expect(created_user).to be_present + expect(created_user.active?).to eq(true) + end - context 'email confirmation' do - context 'when `send_user_confirmation_email` is true' do - before do - stub_application_setting(send_user_confirmation_email: true) - end + it 'does not show any flash message after signing up' do + subject - it 'sends a confirmation email' do - expect { subject } - .to have_enqueued_mail(DeviseMailer, :confirmation_instructions) - end - end - end + expect(flash[:notice]).to be_nil end - end - context 'when the feature is disabled' do - before do - stub_feature_flags(admin_approval_for_new_user_signups: false) - end + it 'does not email the approvers' do + expect(NotificationService).not_to receive(:new) - context 'when the `require_admin_approval_after_user_signup` setting is turned on' do - before do - stub_application_setting(require_admin_approval_after_user_signup: true) - end + subject + end - it 'signs up the user in `active` state' do - subject + context 'email confirmation' do + context 'when `send_user_confirmation_email` is true' do + before do + stub_application_setting(send_user_confirmation_email: true) + end - created_user = User.find_by(email: 'new@user.com') - expect(created_user).to be_present - expect(created_user.active?).to eq(true) + it 'sends a confirmation email' do + expect { subject } + .to have_enqueued_mail(DeviseMailer, :confirmation_instructions) + end end end end @@ -448,45 +413,4 @@ RSpec.describe RegistrationsController do end end end - - describe '#welcome' do - subject { get :welcome } - - it 'renders the devise_experimental_separate_sign_up_flow layout' do - sign_in(create(:user)) - - expected_layout = Gitlab.ee? ? :checkout : :devise_experimental_separate_sign_up_flow - - expect(subject).to render_template(expected_layout) - end - - context '2FA is required from group' do - before do - user = create(:user, require_two_factor_authentication_from_group: true) - sign_in(user) - end - - it 'does not perform a redirect' do - expect(subject).not_to redirect_to(profile_two_factor_auth_path) - end - end - end - - describe '#update_registration' do - subject(:update_registration) do - patch :update_registration, params: { user: { role: 'software_developer', setup_for_company: 'false' } } - end - - context 'without a signed in user' do - it { is_expected.to redirect_to new_user_registration_path } - end - - context 'with a signed in user' do - before do - sign_in(create(:user)) - end - - it { is_expected.to redirect_to(dashboard_projects_path)} - end - end end |