diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-11 03:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-11 03:08:35 +0300 |
commit | 4cdbecb46571861c20908aa6b1dda684f6baf76b (patch) | |
tree | f4a21054d3dbcc79dea420eb0bf6fd66f5b8c60b /spec/controllers | |
parent | 4f584f7b63332ac0ffc5e533a1dde89b0c365728 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
4 files changed, 124 insertions, 23 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 600e1ac223e..e2e5e07fba0 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -37,6 +37,8 @@ RSpec.describe GroupsController do end shared_examples 'details view' do + let(:namespace) { group } + it { is_expected.to render_template('groups/show') } context 'as atom' do @@ -50,6 +52,8 @@ RSpec.describe GroupsController do expect(assigns(:events).map(&:id)).to contain_exactly(event.id) end end + + it_behaves_like 'namespace storage limit alert' end describe 'GET #show' do diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 1c163f6bcb6..8aae9ef85be 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -380,6 +380,15 @@ RSpec.describe ProjectsController do end end end + + context 'namespace storage limit' do + let_it_be(:project) { create(:project, :public, :repository ) } + let(:namespace) { project.namespace } + + subject { get :show, params: { namespace_id: namespace, id: project } } + + it_behaves_like 'namespace storage limit alert' + end end describe 'GET edit' do diff --git a/spec/controllers/registrations/experience_levels_controller_spec.rb b/spec/controllers/registrations/experience_levels_controller_spec.rb new file mode 100644 index 00000000000..e67195cb932 --- /dev/null +++ b/spec/controllers/registrations/experience_levels_controller_spec.rb @@ -0,0 +1,111 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Registrations::ExperienceLevelsController do + let_it_be(:namespace) { create(:group, path: 'group-path' ) } + let_it_be(:user) { create(:user) } + + let(:params) { { namespace_path: namespace.to_param } } + + describe 'GET #show' do + subject { get :show, params: params } + + context 'with an unauthenticated user' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(new_user_session_path) } + end + + context 'with an authenticated user' do + before do + sign_in(user) + stub_experiment_for_user(onboarding_issues: true) + end + + it { is_expected.to have_gitlab_http_status(:ok) } + it { is_expected.to render_template(:show) } + + context 'when not part of the onboarding issues experiment' do + before do + stub_experiment_for_user(onboarding_issues: false) + end + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + end + end + + describe 'PUT/PATCH #update' do + subject { patch :update, params: params } + + context 'with an unauthenticated user' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(new_user_session_path) } + end + + context 'with an authenticated user' do + before do + sign_in(user) + stub_experiment_for_user(onboarding_issues: true) + end + + context 'when not part of the onboarding issues experiment' do + before do + stub_experiment_for_user(onboarding_issues: false) + end + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when user is successfully updated' do + it { is_expected.to set_flash[:message].to('Welcome! You have signed up successfully.') } + + context 'when no experience_level is sent' do + before do + user.user_preference.update_attribute(:experience_level, :novice) + end + + it 'will unset the user’s experience level' do + expect { subject }.to change { user.reload.experience_level }.to(nil) + end + end + + context 'when an expected experience level is sent' do + let(:params) { super().merge(experience_level: :novice) } + + it 'sets the user’s experience level' do + expect { subject }.to change { user.reload.experience_level }.from(nil).to('novice') + end + end + + context 'when an unexpected experience level is sent' do + let(:params) { super().merge(experience_level: :nonexistent) } + + it 'raises an exception' do + expect { subject }.to raise_error(ArgumentError, "'nonexistent' is not a valid experience_level") + end + end + + context 'when a namespace_path is sent' do + it { is_expected.to have_gitlab_http_status(:redirect) } + it { is_expected.to redirect_to(group_path(namespace)) } + end + + 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 redirect_to(root_path) } + end + end + + context 'when user update fails' do + before do + allow_any_instance_of(User).to receive(:save).and_return(false) + end + + it { is_expected.to render_template(:show) } + end + end + end +end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 1993606af04..66caa58666f 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -445,27 +445,4 @@ RSpec.describe RegistrationsController do end end end - - describe '#experience_level' do - subject { get :experience_level } - - let_it_be(:user) { create(:user) } - - let(:part_of_onboarding_issues_experiment) { false } - - before do - stub_experiment_for_user(onboarding_issues: part_of_onboarding_issues_experiment) - sign_in(user) - end - - context 'when not part of the onboarding issues experiment' do - it { is_expected.to have_gitlab_http_status(:not_found) } - end - - context 'when part of the onboarding issues experiment' do - let(:part_of_onboarding_issues_experiment) { true } - - it { is_expected.to render_template(:experience_level) } - end - end end |