summaryrefslogtreecommitdiff
path: root/spec/support/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers')
-rw-r--r--spec/support/helpers/api_helpers.rb13
-rw-r--r--spec/support/helpers/ci/template_helpers.rb4
-rw-r--r--spec/support/helpers/cycle_analytics_helpers.rb25
-rw-r--r--spec/support/helpers/dns_helpers.rb25
-rw-r--r--spec/support/helpers/features/blob_spec_helpers.rb8
-rw-r--r--spec/support/helpers/features/invite_members_modal_helper.rb43
-rw-r--r--spec/support/helpers/features/runners_helpers.rb (renamed from spec/support/helpers/features/runner_helpers.rb)0
-rw-r--r--spec/support/helpers/features/source_editor_spec_helpers.rb5
-rw-r--r--spec/support/helpers/gitaly_setup.rb14
-rw-r--r--spec/support/helpers/global_id_deprecation_helpers.rb8
-rw-r--r--spec/support/helpers/graphql_helpers.rb8
-rw-r--r--spec/support/helpers/javascript_fixtures_helpers.rb21
-rw-r--r--spec/support/helpers/lfs_http_helpers.rb4
-rw-r--r--spec/support/helpers/login_helpers.rb4
-rw-r--r--spec/support/helpers/query_recorder.rb2
-rw-r--r--spec/support/helpers/rack_attack_spec_helpers.rb6
-rw-r--r--spec/support/helpers/redis_commands/recorder.rb34
-rw-r--r--spec/support/helpers/runner_releases_helper.rb22
-rw-r--r--spec/support/helpers/stub_member.rb8
-rw-r--r--spec/support/helpers/stub_method_calls.rb2
-rw-r--r--spec/support/helpers/stubbed_member.rb28
-rw-r--r--spec/support/helpers/type_name_deprecation_helpers.rb15
22 files changed, 237 insertions, 62 deletions
diff --git a/spec/support/helpers/api_helpers.rb b/spec/support/helpers/api_helpers.rb
index fd85071cca3..62bb9576695 100644
--- a/spec/support/helpers/api_helpers.rb
+++ b/spec/support/helpers/api_helpers.rb
@@ -19,15 +19,17 @@ module ApiHelpers
# => "/api/v2/issues?foo=bar&private_token=..."
#
# Returns the relative path to the requested API resource
- def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil, job_token: nil)
+ def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil, job_token: nil, access_token: nil)
full_path = "/api/#{version}#{path}"
if oauth_access_token
- query_string = "access_token=#{oauth_access_token.token}"
+ query_string = "access_token=#{oauth_access_token.plaintext_token}"
elsif personal_access_token
query_string = "private_token=#{personal_access_token.token}"
elsif job_token
query_string = "job_token=#{job_token}"
+ elsif access_token
+ query_string = "access_token=#{access_token.token}"
elsif user
personal_access_token = create(:personal_access_token, user: user)
query_string = "private_token=#{personal_access_token.token}"
@@ -66,6 +68,13 @@ module ApiHelpers
expect(json_response.map { |item| item['id'] }).to contain_exactly(*items)
end
+ def expect_paginated_array_response_contain_exactly(*items)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.map { |item| item['id'] }).to contain_exactly(*items)
+ end
+
def stub_last_activity_update
allow_any_instance_of(Users::ActivityService).to receive(:execute)
end
diff --git a/spec/support/helpers/ci/template_helpers.rb b/spec/support/helpers/ci/template_helpers.rb
index 598a5a0becc..119f8d001a1 100644
--- a/spec/support/helpers/ci/template_helpers.rb
+++ b/spec/support/helpers/ci/template_helpers.rb
@@ -5,6 +5,10 @@ module Ci
def secure_analyzers_prefix
'registry.gitlab.com/security-products'
end
+
+ def template_registry_host
+ 'registry.gitlab.com'
+ end
end
end
diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb
index 044ec56b1cc..05e9a099a2b 100644
--- a/spec/support/helpers/cycle_analytics_helpers.rb
+++ b/spec/support/helpers/cycle_analytics_helpers.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
module CycleAnalyticsHelpers
- include GitHelpers
-
def toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').click
end
@@ -129,10 +127,6 @@ module CycleAnalyticsHelpers
repository = project.repository
oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA
- if Timecop.frozen?
- mock_gitaly_multi_action_dates(repository, commit_time)
- end
-
commit_shas = Array.new(count) do |index|
commit_sha = repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
repository.commit(commit_sha)
@@ -241,23 +235,4 @@ module CycleAnalyticsHelpers
pipeline: dummy_pipeline(project),
protected: false)
end
-
- def mock_gitaly_multi_action_dates(repository, commit_time)
- allow(repository.raw).to receive(:multi_action).and_wrap_original do |m, user, kargs|
- new_date = commit_time || Time.now
- branch_update = m.call(user, **kargs)
-
- if branch_update.newrev
- commit = rugged_repo(repository).rev_parse(branch_update.newrev)
-
- branch_update.newrev = commit.amend(
- update_ref: "#{Gitlab::Git::BRANCH_REF_PREFIX}#{kargs[:branch_name]}",
- author: commit.author.merge(time: new_date),
- committer: commit.committer.merge(time: new_date)
- )
- end
-
- branch_update
- end
- end
end
diff --git a/spec/support/helpers/dns_helpers.rb b/spec/support/helpers/dns_helpers.rb
index b941e7c4808..c60c14f10a3 100644
--- a/spec/support/helpers/dns_helpers.rb
+++ b/spec/support/helpers/dns_helpers.rb
@@ -5,6 +5,7 @@ module DnsHelpers
stub_all_dns!
stub_invalid_dns!
permit_local_dns!
+ permit_postgresql!
end
def permit_dns!
@@ -25,14 +26,30 @@ module DnsHelpers
def permit_local_dns!
local_addresses = %r{
\A
- ::1? | # IPV6
- (127|10)\.0\.0\.\d{1,3} | # 127.0.0.x or 10.0.0.x local network
- (192\.168|172\.16)\.\d{1,3}\.\d{1,3} | # 192.168.x.x or 172.16.x.x local network
- 0\.0\.0\.0 | # loopback
+ ::1? | # IPV6
+ (127|10)\.0\.0\.\d{1,3} | # 127.0.0.x or 10.0.0.x local network
+ 192\.168\.\d{1,3}\.\d{1,3} | # 192.168.x.x local network
+ 172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3} | # 172.16.x.x - 172.31.x.x local network
+ 0\.0\.0\.0 | # loopback
localhost
\z
}xi
allow(Addrinfo).to receive(:getaddrinfo).with(local_addresses, anything, nil, :STREAM).and_call_original
allow(Addrinfo).to receive(:getaddrinfo).with(local_addresses, anything, nil, :STREAM, anything, anything, any_args).and_call_original
end
+
+ # pg v1.4.0, unlike v1.3.5, uses AddrInfo.getaddrinfo to resolve IPv4 and IPv6 addresses:
+ # https://github.com/ged/ruby-pg/pull/459
+ def permit_postgresql!
+ db_hosts.each do |host|
+ next if host.start_with?('/') # Exclude UNIX sockets
+
+ # https://github.com/ged/ruby-pg/blob/252512608a814de16bbad55911f9bbcef0e73cb9/lib/pg/connection.rb#L720
+ allow(Addrinfo).to receive(:getaddrinfo).with(host, anything, nil, :STREAM).and_call_original
+ end
+ end
+
+ def db_hosts
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).map(&:host).compact.uniq
+ end
end
diff --git a/spec/support/helpers/features/blob_spec_helpers.rb b/spec/support/helpers/features/blob_spec_helpers.rb
index 880a7249284..7ccfc9be7e2 100644
--- a/spec/support/helpers/features/blob_spec_helpers.rb
+++ b/spec/support/helpers/features/blob_spec_helpers.rb
@@ -11,12 +11,4 @@ module BlobSpecHelpers
def unset_default_button
set_default_button('')
end
-
- def editor_value
- evaluate_script('monaco.editor.getModels()[0].getValue()')
- end
-
- def set_editor_value(value)
- execute_script("monaco.editor.getModels()[0].setValue('#{value}')")
- end
end
diff --git a/spec/support/helpers/features/invite_members_modal_helper.rb b/spec/support/helpers/features/invite_members_modal_helper.rb
index b56ac5b32c6..d02ec06d886 100644
--- a/spec/support/helpers/features/invite_members_modal_helper.rb
+++ b/spec/support/helpers/features/invite_members_modal_helper.rb
@@ -11,7 +11,7 @@ module Spec
page.within invite_modal_selector do
select_members(names)
choose_options(role, expires_at)
- click_button 'Invite'
+ submit_invites
end
page.refresh if refresh
@@ -42,11 +42,15 @@ module Spec
click_button name
choose_options(role, expires_at)
- click_button 'Invite'
+ submit_invites
page.refresh
end
+ def submit_invites
+ click_button 'Invite'
+ end
+
def choose_options(role, expires_at)
unless role == 'Guest'
click_button 'Guest'
@@ -86,12 +90,47 @@ module Spec
"[data-token-id='#{id}']"
end
+ def more_invite_errors_button_selector
+ "[data-testid='accordion-button']"
+ end
+
+ def limited_invite_error_selector
+ "[data-testid='errors-limited-item']"
+ end
+
+ def expanded_invite_error_selector
+ "[data-testid='errors-expanded-item']"
+ end
+
def remove_token(id)
page.within member_token_selector(id) do
find('[data-testid="close-icon"]').click
end
end
+ def expect_to_have_successful_invite_indicator(page, user)
+ expect(page).to have_selector("#{member_token_selector(user.id)} .gl-bg-green-100")
+ expect(page).not_to have_text("#{user.name}: ")
+ end
+
+ def expect_to_have_invalid_invite_indicator(page, user, message: true)
+ expect(page).to have_selector("#{member_token_selector(user.id)} .gl-bg-red-100")
+ expect(page).to have_selector(member_token_error_selector(user.id))
+ expect(page).to have_text("#{user.name}: Access level should be greater than or equal to") if message
+ end
+
+ def expect_to_have_normal_invite_indicator(page, user)
+ expect(page).to have_selector(member_token_selector(user.id))
+ expect(page).not_to have_selector("#{member_token_selector(user.id)} .gl-bg-red-100")
+ expect(page).not_to have_selector("#{member_token_selector(user.id)} .gl-bg-green-100")
+ expect(page).not_to have_text("#{user.name}: ")
+ end
+
+ def expect_to_have_invite_removed(page, user)
+ expect(page).not_to have_selector(member_token_selector(user.id))
+ expect(page).not_to have_text("#{user.name}: Access level should be greater than or equal to")
+ end
+
def expect_to_have_group(group)
expect(page).to have_selector("[entity-id='#{group.id}']")
end
diff --git a/spec/support/helpers/features/runner_helpers.rb b/spec/support/helpers/features/runners_helpers.rb
index 63fc628358c..63fc628358c 100644
--- a/spec/support/helpers/features/runner_helpers.rb
+++ b/spec/support/helpers/features/runners_helpers.rb
diff --git a/spec/support/helpers/features/source_editor_spec_helpers.rb b/spec/support/helpers/features/source_editor_spec_helpers.rb
index cdc59f9cbe1..f7eb2a52507 100644
--- a/spec/support/helpers/features/source_editor_spec_helpers.rb
+++ b/spec/support/helpers/features/source_editor_spec_helpers.rb
@@ -12,8 +12,11 @@ module Spec
def editor_set_value(value)
editor = find('.monaco-editor')
uri = editor['data-uri']
+ execute_script("localMonaco.getModel('#{uri}').setValue('#{escape_javascript(value)}')")
- execute_script("monaco.editor.getModel('#{uri}').setValue('#{escape_javascript(value)}')")
+ # We only check that the first line is present because when the content is long,
+ # only a part of the text will be rendered in the DOM due to scrolling
+ page.has_selector?('.gl-source-editor .view-lines', text: value.lines.first)
end
end
end
diff --git a/spec/support/helpers/gitaly_setup.rb b/spec/support/helpers/gitaly_setup.rb
index 56993fc27b7..278dc79e1d0 100644
--- a/spec/support/helpers/gitaly_setup.rb
+++ b/spec/support/helpers/gitaly_setup.rb
@@ -12,6 +12,8 @@ require 'logger'
require 'fileutils'
require 'bundler'
+require_relative '../../../lib/gitlab/utils'
+
module GitalySetup
extend self
@@ -139,7 +141,7 @@ module GitalySetup
end
def start_praefect
- if ENV['GITALY_PRAEFECT_WITH_DB']
+ if praefect_with_db?
LOGGER.debug 'Starting Praefect with database election strategy'
start(:praefect, File.join(tmp_tests_gitaly_dir, 'praefect-db.config.toml'))
else
@@ -290,7 +292,7 @@ module GitalySetup
# In CI we need to pre-generate both config files.
# For local testing we'll create the correct file on-demand.
- if ENV['CI'] || ENV['GITALY_PRAEFECT_WITH_DB'].nil?
+ if ENV['CI'] || !praefect_with_db?
Gitlab::SetupHelper::Praefect.create_configuration(
gitaly_dir,
{ 'praefect' => repos_path },
@@ -298,7 +300,7 @@ module GitalySetup
)
end
- if ENV['CI'] || ENV['GITALY_PRAEFECT_WITH_DB']
+ if ENV['CI'] || praefect_with_db?
Gitlab::SetupHelper::Praefect.create_configuration(
gitaly_dir,
{ 'praefect' => repos_path },
@@ -319,7 +321,7 @@ module GitalySetup
end
def setup_praefect
- return unless ENV['GITALY_PRAEFECT_WITH_DB']
+ return unless praefect_with_db?
migrate_cmd = service_cmd(:praefect, File.join(tmp_tests_gitaly_dir, 'praefect-db.config.toml')) + ['sql-migrate']
system(env, *migrate_cmd, [:out, :err] => 'log/praefect-test.log')
@@ -396,4 +398,8 @@ module GitalySetup
def praefect_binary
File.join(tmp_tests_gitaly_dir, "_build", "bin", "praefect")
end
+
+ def praefect_with_db?
+ Gitlab::Utils.to_boolean(ENV['GITALY_PRAEFECT_WITH_DB'], default: false)
+ end
end
diff --git a/spec/support/helpers/global_id_deprecation_helpers.rb b/spec/support/helpers/global_id_deprecation_helpers.rb
index 37ba1420fb3..5c6862ca84a 100644
--- a/spec/support/helpers/global_id_deprecation_helpers.rb
+++ b/spec/support/helpers/global_id_deprecation_helpers.rb
@@ -2,9 +2,11 @@
module GlobalIDDeprecationHelpers
def stub_global_id_deprecations(*deprecations)
- old_name_map = deprecations.index_by(&:old_model_name)
- new_name_map = deprecations.index_by(&:new_model_name)
- old_graphql_name_map = deprecations.index_by { |d| Types::GlobalIDType.model_name_to_graphql_name(d.old_model_name) }
+ old_name_map = deprecations.index_by(&:old_name)
+ new_name_map = deprecations.index_by(&:new_name)
+ old_graphql_name_map = deprecations.index_by do |d|
+ Gitlab::GlobalId::Deprecations.map_graphql_name(d.old_name)
+ end
stub_const('Gitlab::GlobalId::Deprecations::OLD_NAME_MAP', old_name_map)
stub_const('Gitlab::GlobalId::Deprecations::NEW_NAME_MAP', new_name_map)
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index d0a1941817a..d78c523decd 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -170,7 +170,7 @@ module GraphqlHelpers
# or `prepare` in app/graphql/types/range_input_type.rb, used by Types::TimeframeInputType
def args_internal(field, args:, query_ctx:, parent:, extras:, query:)
arguments = GraphqlHelpers.deep_transform_args(args, field)
- arguments.merge!(extras.reject {|k, v| v == :not_given})
+ arguments.merge!(extras.reject { |k, v| v == :not_given })
end
# Pros:
@@ -185,7 +185,7 @@ module GraphqlHelpers
# take internal style args, and force them into client style args
def args_internal_prepared(field, args:, query_ctx:, parent:, extras:, query:)
arguments = GraphqlHelpers.as_graphql_argument_literals(args)
- arguments.merge!(extras.reject {|k, v| v == :not_given})
+ arguments.merge!(extras.reject { |k, v| v == :not_given })
# Use public API to properly prepare the args for use by the resolver.
# It uses `coerce_arguments` under the covers
@@ -307,14 +307,14 @@ module GraphqlHelpers
end
def graphql_mutation(name, input, fields = nil, &block)
- raise ArgumentError, 'Please pass either `fields` parameter or a block to `#graphql_mutation`, but not both.' if fields.present? && block_given?
+ raise ArgumentError, 'Please pass either `fields` parameter or a block to `#graphql_mutation`, but not both.' if fields.present? && block
name = name.graphql_name if name.respond_to?(:graphql_name)
mutation_name = GraphqlHelpers.fieldnamerize(name)
input_variable_name = "$#{input_variable_name_for_mutation(name)}"
mutation_field = GitlabSchema.mutation.fields[mutation_name]
- fields = yield if block_given?
+ fields = yield if block
fields ||= all_graphql_fields_for(mutation_field.type.to_type_signature)
query = <<~MUTATION
diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb
index 84cd0181533..32e6e8d50bd 100644
--- a/spec/support/helpers/javascript_fixtures_helpers.rb
+++ b/spec/support/helpers/javascript_fixtures_helpers.rb
@@ -2,6 +2,7 @@
require 'action_dispatch/testing/test_request'
require 'fileutils'
+require 'graphlyte'
require_relative '../../../lib/gitlab/popen'
@@ -47,7 +48,8 @@ module JavaScriptFixturesHelpers
path = Rails.root / base / query_path
queries = Gitlab::Graphql::Queries.find(path)
if queries.length == 1
- queries.first.text(mode: Gitlab.ee? ? :ee : :ce )
+ query = queries.first.text(mode: Gitlab.ee? ? :ee : :ce )
+ inflate_query_with_typenames(query)
else
raise "Could not find query file at #{path}, please check your query_path" % path
end
@@ -55,6 +57,23 @@ module JavaScriptFixturesHelpers
private
+ # Private: Parse a GraphQL query and inflate the fields with a __typename
+ #
+ # query - the GraqhQL query to parse
+ def inflate_query_with_typenames(query, doc: Graphlyte.parse(query))
+ typename_editor.edit(doc)
+
+ doc.to_s
+ end
+
+ def typename_editor
+ typename = Graphlyte::Syntax::Field.new(name: '__typename')
+
+ @editor ||= Graphlyte::Editor.new.on_field do |field|
+ field.selection << typename unless field.selection.empty? || field.selection.map(&:name).include?('__typename')
+ end
+ end
+
# Private: Store a response object as fixture file
#
# response - string or response object to store
diff --git a/spec/support/helpers/lfs_http_helpers.rb b/spec/support/helpers/lfs_http_helpers.rb
index 199d5e70e32..91ed56b4d13 100644
--- a/spec/support/helpers/lfs_http_helpers.rb
+++ b/spec/support/helpers/lfs_http_helpers.rb
@@ -52,11 +52,9 @@ module LfsHttpHelpers
end
def request_body(operation, objects)
- objects = [objects] unless objects.is_a?(Array)
-
{
'operation' => operation,
- 'objects' => objects
+ 'objects' => Array.wrap(objects)
}
end
end
diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb
index c93ef8b0ead..f83f5c7bfde 100644
--- a/spec/support/helpers/login_helpers.rb
+++ b/spec/support/helpers/login_helpers.rb
@@ -91,12 +91,12 @@ module LoginHelpers
# user - User instance to login with
# remember - Whether or not to check "Remember me" (default: false)
# two_factor_auth - If two-factor authentication is enabled (default: false)
- # password - password to attempt to login with
+ # password - password to attempt to login with (default: user.password)
def gitlab_sign_in_with(user, remember: false, two_factor_auth: false, password: nil)
visit new_user_session_path
fill_in "user_login", with: user.email
- fill_in "user_password", with: (password || "12345678")
+ fill_in "user_password", with: (password || user.password)
check 'user_remember_me' if remember
find('[data-testid="sign-in-button"]:enabled').click
diff --git a/spec/support/helpers/query_recorder.rb b/spec/support/helpers/query_recorder.rb
index 01839a74e65..dd124ed9c7f 100644
--- a/spec/support/helpers/query_recorder.rb
+++ b/spec/support/helpers/query_recorder.rb
@@ -14,7 +14,7 @@ module ActiveRecord
@skip_schema_queries = skip_schema_queries
@query_recorder_debug = ENV['QUERY_RECORDER_DEBUG'] || query_recorder_debug
@log_file = log_file
- record(&block) if block_given?
+ record(&block) if block
end
def record(&block)
diff --git a/spec/support/helpers/rack_attack_spec_helpers.rb b/spec/support/helpers/rack_attack_spec_helpers.rb
index 6c06781df03..2502889e17c 100644
--- a/spec/support/helpers/rack_attack_spec_helpers.rb
+++ b/spec/support/helpers/rack_attack_spec_helpers.rb
@@ -17,8 +17,12 @@ module RackAttackSpecHelpers
{ Gitlab::Auth::AuthFinders::PRIVATE_TOKEN_HEADER => personal_access_token.token }
end
+ def bearer_headers(token)
+ { 'AUTHORIZATION' => "Bearer #{token.token}" }
+ end
+
def oauth_token_headers(oauth_access_token)
- { 'AUTHORIZATION' => "Bearer #{oauth_access_token.token}" }
+ { 'AUTHORIZATION' => "Bearer #{oauth_access_token.plaintext_token}" }
end
def basic_auth_headers(user, personal_access_token)
diff --git a/spec/support/helpers/redis_commands/recorder.rb b/spec/support/helpers/redis_commands/recorder.rb
new file mode 100644
index 00000000000..05a1aa67853
--- /dev/null
+++ b/spec/support/helpers/redis_commands/recorder.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module RedisCommands
+ class Recorder
+ def initialize(pattern: nil, &block)
+ @log = []
+ @pattern = pattern
+
+ record(&block) if block
+ end
+
+ attr_reader :log
+
+ def record(&block)
+ ActiveSupport::Notifications.subscribed(method(:callback), 'redis.process_commands', &block)
+ end
+
+ def by_command(command)
+ @log.select { |record| record.include?(command) }
+ end
+
+ def count
+ @count ||= @log.count
+ end
+
+ private
+
+ def callback(name, start, finish, message_id, values)
+ commands = values[:commands]
+
+ @log << commands.flatten if @pattern.nil? || commands.to_s.include?(@pattern)
+ end
+ end
+end
diff --git a/spec/support/helpers/runner_releases_helper.rb b/spec/support/helpers/runner_releases_helper.rb
new file mode 100644
index 00000000000..ab16a705425
--- /dev/null
+++ b/spec/support/helpers/runner_releases_helper.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module RunnerReleasesHelper
+ def stub_runner_releases(available_runner_releases, gitlab_version: nil)
+ # We stub the behavior of RunnerReleases so that we don't need to rely on flaky global settings
+ available_runner_releases = available_runner_releases
+ .map { |v| ::Gitlab::VersionInfo.parse(v, parse_suffix: true) }
+ .sort
+ releases_by_minor = available_runner_releases
+ .group_by(&:without_patch)
+ .transform_values(&:max)
+
+ runner_releases_double = instance_double(Gitlab::Ci::RunnerReleases)
+ allow(::Gitlab::Ci::RunnerUpgradeCheck).to receive(:new).and_wrap_original do |method, *_original_args|
+ gitlab_version ||= available_runner_releases.max
+ method.call(gitlab_version, runner_releases_double)
+ end
+
+ allow(runner_releases_double).to receive(:releases).and_return(available_runner_releases)
+ allow(runner_releases_double).to receive(:releases_by_minor).and_return(releases_by_minor)
+ end
+end
diff --git a/spec/support/helpers/stub_member.rb b/spec/support/helpers/stub_member.rb
new file mode 100644
index 00000000000..bcd0b675041
--- /dev/null
+++ b/spec/support/helpers/stub_member.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+module StubMember
+ def self.included(base)
+ Member.prepend(StubbedMember::Member)
+ ProjectMember.prepend(StubbedMember::ProjectMember)
+ end
+end
diff --git a/spec/support/helpers/stub_method_calls.rb b/spec/support/helpers/stub_method_calls.rb
index 45d704958ca..ccbede16563 100644
--- a/spec/support/helpers/stub_method_calls.rb
+++ b/spec/support/helpers/stub_method_calls.rb
@@ -44,7 +44,7 @@ module StubMethodCalls
end
def self.stub_method(object, method, &block)
- raise ArgumentError, "Block is required" unless block_given?
+ raise ArgumentError, "Block is required" unless block
backup_method(object, method) unless backed_up_method?(object, method)
object.define_singleton_method(method, &block)
diff --git a/spec/support/helpers/stubbed_member.rb b/spec/support/helpers/stubbed_member.rb
new file mode 100644
index 00000000000..27420c9b709
--- /dev/null
+++ b/spec/support/helpers/stubbed_member.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+# Extend the ProjectMember & GroupMember class with the ability to
+# to run project_authorizations refresh jobs inline.
+
+# This is needed so that calls like `group.add_member(user, access_level)` or `create(:project_member)`
+# in the specs can be run without including `:sidekiq_inline` trait.
+module StubbedMember
+ extend ActiveSupport::Concern
+
+ module Member
+ private
+
+ def refresh_member_authorized_projects(blocking:)
+ return super unless blocking
+
+ AuthorizedProjectsWorker.new.perform(user_id)
+ end
+ end
+
+ module ProjectMember
+ private
+
+ def blocking_project_authorizations_refresh
+ AuthorizedProjectUpdate::ProjectRecalculatePerUserWorker.new.perform(project.id, user.id)
+ end
+ end
+end
diff --git a/spec/support/helpers/type_name_deprecation_helpers.rb b/spec/support/helpers/type_name_deprecation_helpers.rb
new file mode 100644
index 00000000000..591737ab532
--- /dev/null
+++ b/spec/support/helpers/type_name_deprecation_helpers.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module TypeNameDeprecationHelpers
+ def stub_type_name_deprecations(*deprecations)
+ old_name_map = deprecations.index_by(&:old_name)
+ new_name_map = deprecations.index_by(&:new_name)
+ old_graphql_name_map = deprecations.index_by do |d|
+ Gitlab::Graphql::TypeNameDeprecations.map_graphql_name(d.old_name)
+ end
+
+ stub_const('Gitlab::Graphql::TypeNameDeprecations::OLD_NAME_MAP', old_name_map)
+ stub_const('Gitlab::Graphql::TypeNameDeprecations::NEW_NAME_MAP', new_name_map)
+ stub_const('Gitlab::Graphql::TypeNameDeprecations::OLD_GRAPHQL_NAME_MAP', old_graphql_name_map)
+ end
+end