Commit b7634cfb authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch '332442-flaky-test-ee-spec-requests-api-vulnerabilities_spec-rb-166-api-vulnerabilities-post' into 'master'

RSpec access matcher: Remove patched user after matcher is run

See merge request gitlab-org/gitlab!63099
parents 04e26c94 17f9c9e3
# frozen_string_literal: true
module AccessMatchersHelpers
include Gitlab::Utils::StrongMemoize
USER_ACCESSOR_METHOD_NAME = 'user'
def provide_user(role, membership = nil)
......@@ -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`.
# This override is per concrete example only because the example group class gets re-created for each example.
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}
@#{USER_ACCESSOR_METHOD_NAME} ||= User.find(#{user.id})
end
......@@ -81,6 +78,13 @@ module AccessMatchersHelpers
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)
raise_if_non_block_expectation!(action)
......@@ -91,5 +95,7 @@ module AccessMatchersHelpers
else
action.call
end
reset_matcher_environment
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment