diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 15:06:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 15:06:00 +0300 |
commit | 5707f305f4b961e24369fcdaecf0b8ce1c34bad8 (patch) | |
tree | 3b291653b83b3e6c2bffc77c54527fbe6f6373be /spec/helpers | |
parent | 759cd6c2985088d187ed519f2a881c2c690b34ec (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/nav_helper_spec.rb | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb index 979d89812f5..ff2be795d87 100644 --- a/spec/helpers/nav_helper_spec.rb +++ b/spec/helpers/nav_helper_spec.rb @@ -1,16 +1,20 @@ require 'spec_helper' -describe NavHelper do +describe NavHelper, :do_not_mock_admin_mode do describe '#header_links' do + include_context 'custom session' + before do - allow(helper).to receive(:session) { {} } + allow(helper).to receive(:session).and_return(session) end context 'when the user is logged in' do - let(:user) { build(:user) } + let(:user) { create(:user) } + let(:current_user_mode) { Gitlab::Auth::CurrentUserMode.new(user) } before do allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive(:current_user_mode).and_return(current_user_mode) allow(helper).to receive(:can?) { true } end @@ -26,6 +30,46 @@ describe NavHelper do expect(helper.header_links).to include(:admin_impersonation) end + context 'as admin' do + let(:user) { create(:user, :admin) } + + context 'feature flag :user_mode_in_session is enabled' do + it 'does not contain the admin mode link by default' do + expect(helper.header_links).not_to include(:admin_mode) + end + + context 'with admin mode enabled' do + before do + current_user_mode.enable_admin_mode!(password: user.password) + end + + it 'contains the admin mode link' do + expect(helper.header_links).to include(:admin_mode) + end + end + end + + context 'feature flag :user_mode_in_session is disabled' do + before do + stub_feature_flags(user_mode_in_session: false) + end + + it 'does not contain the admin mode link' do + expect(helper.header_links).not_to include(:admin_mode) + end + + context 'with admin mode enabled' do + before do + current_user_mode.enable_admin_mode!(password: user.password) + end + + it 'has no effect on header links' do + expect(helper.header_links).not_to include(:admin_mode) + end + end + end + end + context 'when the user cannot read cross project' do before do allow(helper).to receive(:can?).with(user, :read_cross_project) { false } |