Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
06e78f6d
Commit
06e78f6d
authored
Mar 24, 2020
by
Diego Louzán
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conditional mocking of admin mode in specs based on directory
parent
c5e82147
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
+57
-5
changelogs/unreleased/chore-conditional-mocking-admin-mode-specs.yml
...unreleased/chore-conditional-mocking-admin-mode-specs.yml
+5
-0
spec/spec_helper.rb
spec/spec_helper.rb
+52
-5
No files found.
changelogs/unreleased/chore-conditional-mocking-admin-mode-specs.yml
0 → 100644
View file @
06e78f6d
---
title
:
Conditional mocking of admin mode in specs by directory
merge_request
:
28420
author
:
Diego Louzán
type
:
other
spec/spec_helper.rb
View file @
06e78f6d
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment