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
17f9c9e3
Commit
17f9c9e3
authored
Jun 02, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove patched user after matcher is run
parent
9f5f1405
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
spec/support/helpers/access_matchers_helpers.rb
spec/support/helpers/access_matchers_helpers.rb
+11
-5
No files found.
spec/support/helpers/access_matchers_helpers.rb
View file @
17f9c9e3
# frozen_string_literal: true
# frozen_string_literal: true
module
AccessMatchersHelpers
module
AccessMatchersHelpers
include
Gitlab
::
Utils
::
StrongMemoize
USER_ACCESSOR_METHOD_NAME
=
'user'
USER_ACCESSOR_METHOD_NAME
=
'user'
def
provide_user
(
role
,
membership
=
nil
)
def
provide_user
(
role
,
membership
=
nil
)
...
@@ -61,11 +63,6 @@ module AccessMatchersHelpers
...
@@ -61,11 +63,6 @@ module AccessMatchersHelpers
# (or defined by `method_name`) method generated by `let` definition in example group before it's used by `subject`.
# (or defined by `method_name`) method generated by `let` definition in example group before it's used by `subject`.
# This override is per concrete example only because the example group class gets re-created for each example.
# This override is per concrete example only because the example group class gets re-created for each example.
instance_eval
(
<<~
CODE
,
__FILE__
,
__LINE__
+
1
)
instance_eval
(
<<~
CODE
,
__FILE__
,
__LINE__
+
1
)
if instance_variable_get(:@__
#{
USER_ACCESSOR_METHOD_NAME
}
_patched)
raise ArgumentError, 'An access matcher be_allowed_for/be_denied_for can be used only once per example (`it` block)'
end
instance_variable_set(:@__
#{
USER_ACCESSOR_METHOD_NAME
}
_patched, true)
def
#{
USER_ACCESSOR_METHOD_NAME
}
def
#{
USER_ACCESSOR_METHOD_NAME
}
@
#{
USER_ACCESSOR_METHOD_NAME
}
||= User.find(
#{
user
.
id
}
)
@
#{
USER_ACCESSOR_METHOD_NAME
}
||= User.find(
#{
user
.
id
}
)
end
end
...
@@ -81,6 +78,13 @@ module AccessMatchersHelpers
...
@@ -81,6 +78,13 @@ module AccessMatchersHelpers
end
end
end
end
def
reset_matcher_environment
instance_eval
(
<<~
CODE
,
__FILE__
,
__LINE__
+
1
)
clear_memoization(:
#{
USER_ACCESSOR_METHOD_NAME
}
)
undef
#{
USER_ACCESSOR_METHOD_NAME
}
if defined? user
CODE
end
def
run_matcher
(
action
,
role
,
membership
,
owned_objects
)
def
run_matcher
(
action
,
role
,
membership
,
owned_objects
)
raise_if_non_block_expectation!
(
action
)
raise_if_non_block_expectation!
(
action
)
...
@@ -91,5 +95,7 @@ module AccessMatchersHelpers
...
@@ -91,5 +95,7 @@ module AccessMatchersHelpers
else
else
action
.
call
action
.
call
end
end
reset_matcher_environment
end
end
end
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