Commit 95f2bd92 authored by Dallas Reedy's avatar Dallas Reedy

Ensure we always have a namespace_path param

parent f9f3f399
...@@ -7,13 +7,14 @@ module Registrations ...@@ -7,13 +7,14 @@ module Registrations
layout 'devise_experimental_separate_sign_up_flow' layout 'devise_experimental_separate_sign_up_flow'
before_action :check_experiment_enabled before_action :check_experiment_enabled
before_action :ensure_namespace_path_param
def update def update
current_user.experience_level = params[:experience_level] current_user.experience_level = params[:experience_level]
if current_user.save if current_user.save
flash[:message] = I18n.t('devise.registrations.signed_up') flash[:message] = I18n.t('devise.registrations.signed_up')
redirect_to group_path(params[:namespace_path] || current_user) redirect_to group_path(params[:namespace_path])
else else
render :show render :show
end end
...@@ -24,5 +25,9 @@ module Registrations ...@@ -24,5 +25,9 @@ module Registrations
def check_experiment_enabled def check_experiment_enabled
access_denied! unless experiment_enabled?(:onboarding_issues) access_denied! unless experiment_enabled?(:onboarding_issues)
end end
def ensure_namespace_path_param
redirect_to root_path unless params[:namespace_path].present?
end
end end
end end
...@@ -16,7 +16,7 @@ module Registrations ...@@ -16,7 +16,7 @@ module Registrations
if @project.saved? if @project.saved?
create_learn_gitlab_project create_learn_gitlab_project
redirect_to users_sign_up_experience_level_path(namespace_path: @project.namespace.to_param) redirect_to users_sign_up_experience_level_path(namespace_path: @project.namespace)
else else
render :new render :new
end end
......
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
require 'spec_helper' require 'spec_helper'
describe Registrations::ExperienceLevelsController do describe Registrations::ExperienceLevelsController do
let_it_be(:namespace) { create(:group, path: 'group-path' ) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:params) { { namespace_path: namespace.to_param } }
describe 'GET #show' do describe 'GET #show' do
subject { get :show } subject { get :show, params: params }
context 'with an unauthenticated user' do context 'with an unauthenticated user' do
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
...@@ -35,10 +38,6 @@ describe Registrations::ExperienceLevelsController do ...@@ -35,10 +38,6 @@ describe Registrations::ExperienceLevelsController do
describe 'PUT/PATCH #update' do describe 'PUT/PATCH #update' do
subject { patch :update, params: params } subject { patch :update, params: params }
let_it_be(:namespace) { create(:group, path: 'group-path' ) }
let(:params) { {} }
context 'with an unauthenticated user' do context 'with an unauthenticated user' do
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
it { is_expected.to redirect_to(new_user_session_path) } it { is_expected.to redirect_to(new_user_session_path) }
...@@ -72,15 +71,15 @@ describe Registrations::ExperienceLevelsController do ...@@ -72,15 +71,15 @@ describe Registrations::ExperienceLevelsController do
end end
context 'when an expected experience level is sent' do context 'when an expected experience level is sent' do
let(:params) { { experience_level: :novice } } let(:params) { super().merge(experience_level: :novice) }
it 'sets the user’s experience level' do it 'sets the user’s experience level' do
expect { subject }.to change { user.reload.experience_level }.to('novice') expect { subject }.to change { user.reload.experience_level }.from(nil).to('novice')
end end
end end
context 'when an unexpected experience level is sent' do context 'when an unexpected experience level is sent' do
let(:params) { { experience_level: :nonexistent } } let(:params) { super().merge(experience_level: :nonexistent) }
it 'raises an exception' do it 'raises an exception' do
expect { subject }.to raise_error(ArgumentError, "'nonexistent' is not a valid experience_level") expect { subject }.to raise_error(ArgumentError, "'nonexistent' is not a valid experience_level")
...@@ -88,15 +87,15 @@ describe Registrations::ExperienceLevelsController do ...@@ -88,15 +87,15 @@ describe Registrations::ExperienceLevelsController do
end end
context 'when a namespace_path is sent' do context 'when a namespace_path is sent' do
let(:params) { { namespace_path: namespace.to_param } }
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
it { is_expected.to redirect_to(group_path(namespace)) } it { is_expected.to redirect_to(group_path(namespace)) }
end end
context 'when no namespace_path is sent' do context 'when no namespace_path is sent' do
let(:params) { super().merge(namespace_path: nil) }
it { is_expected.to have_gitlab_http_status(:redirect) } it { is_expected.to have_gitlab_http_status(:redirect) }
it { is_expected.to redirect_to(user_path(user)) } it { is_expected.to redirect_to(root_path) }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment