Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 15:08:00 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 15:08:00 +0300
commit1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (patch)
treeddb78a8a0d1350dc767f049a21e0f7d37edaa82c /spec/spec_helper.rb
parentb11f7057d067885619ee3e513751f180b2e8ad85 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb57
1 files changed, 52 insertions, 5 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 30524e4bbae..08320934ba1 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -214,15 +214,62 @@ RSpec.configure do |config|
# modifying a significant number of specs to test both states for admin
# mode enabled / disabled.
#
- # See https://gitlab.com/gitlab-org/gitlab/issues/31511
- # See gitlab/spec/support/helpers/admin_mode_helpers.rb
+ # This will only be applied to specs below dirs in `admin_mode_mock_dirs`
#
- # If it is required to have the real behaviour that an admin is signed in
+ # See ongoing migration: https://gitlab.com/gitlab-org/gitlab/-/issues/31511
+ #
+ # Until the migration is finished, if it is required to have the real
+ # behaviour in any of the mocked dirs specs that an admin is signed in
# with normal user mode and needs to switch to admin mode, it is possible to
# mark such tests with the `do_not_mock_admin_mode` metadata tag, e.g:
#
- # context 'some test with normal user mode', :do_not_mock_admin_mode do ... end
- unless example.metadata[:do_not_mock_admin_mode]
+ # context 'some test in mocked dir', :do_not_mock_admin_mode do ... end
+ admin_mode_mock_dirs = %w(
+ ./ee/spec/controllers
+ ./ee/spec/elastic_integration
+ ./ee/spec/features
+ ./ee/spec/finders
+ ./ee/spec/lib
+ ./ee/spec/models
+ ./ee/spec/policies
+ ./ee/spec/requests/admin
+ ./ee/spec/serializers
+ ./ee/spec/services
+ ./ee/spec/support/protected_tags
+ ./ee/spec/support/shared_examples
+ ./spec/controllers
+ ./spec/features
+ ./spec/finders
+ ./spec/frontend
+ ./spec/helpers
+ ./spec/lib
+ ./spec/models
+ ./spec/policies
+ ./spec/requests
+ ./spec/serializers
+ ./spec/services
+ ./spec/support/cycle_analytics_helpers
+ ./spec/support/protected_tags
+ ./spec/support/shared_examples
+ ./spec/views
+ ./spec/workers
+ )
+
+ if !example.metadata[:do_not_mock_admin_mode] && example.metadata[:file_path].start_with?(*admin_mode_mock_dirs)
+ allow_any_instance_of(Gitlab::Auth::CurrentUserMode).to receive(:admin_mode?) do |current_user_mode|
+ current_user_mode.send(:user)&.admin?
+ end
+ end
+
+ # Administrators have to re-authenticate in order to access administrative
+ # functionality when feature flag :user_mode_in_session is active. Any spec
+ # that requires administrative access can use the tag :enable_admin_mode
+ # to avoid the second auth step (provided the user is already an admin):
+ #
+ # context 'some test that requires admin mode', :enable_admin_mode do ... end
+ #
+ # See also spec/support/helpers/admin_mode_helpers.rb
+ if example.metadata[:enable_admin_mode]
allow_any_instance_of(Gitlab::Auth::CurrentUserMode).to receive(:admin_mode?) do |current_user_mode|
current_user_mode.send(:user)&.admin?
end