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:
-rw-r--r--.rubocop_todo.yml8
-rw-r--r--CONTRIBUTING.md8
-rw-r--r--Gemfile.lock2
-rw-r--r--app/models/concerns/avatarable.rb5
-rw-r--r--app/models/concerns/routable.rb7
-rw-r--r--app/models/group.rb4
-rw-r--r--app/uploaders/gitlab_uploader.rb4
-rw-r--r--app/views/admin/application_settings/_repository_storage.html.haml2
-rw-r--r--changelogs/unreleased/42936-improve-ns-factory-avoid-duplicates.yml6
-rw-r--r--changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml5
-rw-r--r--config/initializers/1_settings.rb129
-rw-r--r--config/initializers/2_app.rb8
-rw-r--r--db/fixtures/development/17_cycle_analytics.rb2
-rw-r--r--doc/development/testing_guide/best_practices.md36
-rw-r--r--doc/development/testing_guide/testing_rake_tasks.md2
-rw-r--r--doc/user/project/deploy_tokens/index.md2
-rw-r--r--features/support/env.rb6
-rw-r--r--lib/api/helpers/notes_helpers.rb4
-rw-r--r--lib/gitlab.rb13
-rw-r--r--lib/gitlab/git.rb2
-rw-r--r--lib/settings.rb126
-rw-r--r--rubocop/spec_helpers.rb2
-rw-r--r--spec/controllers/import/bitbucket_controller_spec.rb5
-rw-r--r--spec/controllers/import/gitlab_controller_spec.rb5
-rw-r--r--spec/controllers/projects/forks_controller_spec.rb6
-rw-r--r--spec/factories/commits.rb2
-rw-r--r--spec/factories/gpg_key_subkeys.rb2
-rw-r--r--spec/factories/gpg_keys.rb2
-rw-r--r--spec/factories/gpg_signature.rb2
-rw-r--r--spec/factories/groups.rb8
-rw-r--r--spec/factories/namespaces.rb18
-rw-r--r--spec/factories/notes.rb2
-rw-r--r--spec/factories/projects.rb2
-rw-r--r--spec/fast_spec_helper.rb15
-rw-r--r--spec/features/projects/new_project_spec.rb4
-rw-r--r--spec/lib/gitlab/bitbucket_import/project_creator_spec.rb2
-rw-r--r--spec/lib/gitlab/gitlab_import/project_creator_spec.rb2
-rw-r--r--spec/lib/gitlab/google_code_import/project_creator_spec.rb2
-rw-r--r--spec/lib/gitlab/legacy_github_import/project_creator_spec.rb2
-rw-r--r--spec/lib/gitlab_spec.rb10
-rw-r--r--spec/models/concerns/avatarable_spec.rb16
-rw-r--r--spec/models/project_spec.rb2
-rw-r--r--spec/models/user_spec.rb8
-rw-r--r--spec/services/groups/nested_create_service_spec.rb7
-rw-r--r--spec/spec_helper.rb59
-rw-r--r--spec/support/capybara.rb2
-rw-r--r--spec/support/controllers/githubish_import_controller_shared_examples.rb9
-rw-r--r--spec/support/factory_bot.rb3
-rwxr-xr-xspec/support/generate-seed-repo-rb2
-rw-r--r--spec/support/gitlab-git-test.git/README.md2
-rw-r--r--spec/support/helpers/api_helpers.rb (renamed from spec/support/api_helpers.rb)0
-rw-r--r--spec/support/helpers/bare_repo_operations.rb (renamed from spec/support/bare_repo_operations.rb)0
-rw-r--r--spec/support/helpers/board_helpers.rb (renamed from spec/support/board_helpers.rb)0
-rw-r--r--spec/support/helpers/capybara_helpers.rb (renamed from spec/support/capybara_helpers.rb)4
-rw-r--r--spec/support/helpers/cookie_helper.rb (renamed from spec/support/cookie_helper.rb)0
-rw-r--r--spec/support/helpers/cycle_analytics_helpers.rb (renamed from spec/support/cycle_analytics_helpers.rb)4
-rw-r--r--spec/support/helpers/database_connection_helpers.rb (renamed from spec/support/database_connection_helpers.rb)0
-rw-r--r--spec/support/helpers/devise_helpers.rb (renamed from spec/support/devise_helpers.rb)0
-rw-r--r--spec/support/helpers/drag_to_helper.rb (renamed from spec/support/drag_to_helper.rb)0
-rw-r--r--spec/support/helpers/dropzone_helper.rb (renamed from spec/support/dropzone_helper.rb)0
-rw-r--r--spec/support/helpers/email_helpers.rb (renamed from spec/support/email_helpers.rb)0
-rw-r--r--spec/support/helpers/fake_migration_classes.rb (renamed from spec/support/fake_migration_classes.rb)0
-rw-r--r--spec/support/helpers/fake_u2f_device.rb (renamed from spec/support/fake_u2f_device.rb)0
-rw-r--r--spec/support/helpers/filter_item_select_helper.rb (renamed from spec/support/filter_item_select_helper.rb)0
-rw-r--r--spec/support/helpers/filter_spec_helper.rb (renamed from spec/support/filter_spec_helper.rb)0
-rw-r--r--spec/support/helpers/filtered_search_helpers.rb (renamed from spec/support/filtered_search_helpers.rb)0
-rw-r--r--spec/support/helpers/fixture_helpers.rb (renamed from spec/support/fixture_helpers.rb)4
-rw-r--r--spec/support/helpers/git_http_helpers.rb (renamed from spec/support/git_http_helpers.rb)0
-rw-r--r--spec/support/helpers/gitlab_verify_helpers.rb25
-rw-r--r--spec/support/helpers/gpg_helpers.rb (renamed from spec/support/gpg_helpers.rb)0
-rw-r--r--spec/support/helpers/import_spec_helper.rb (renamed from spec/support/import_spec_helper.rb)0
-rw-r--r--spec/support/helpers/input_helper.rb (renamed from spec/support/input_helper.rb)0
-rw-r--r--spec/support/helpers/inspect_requests.rb (renamed from spec/support/inspect_requests.rb)0
-rw-r--r--spec/support/helpers/issue_helpers.rb (renamed from spec/support/issue_helpers.rb)0
-rw-r--r--spec/support/helpers/javascript_fixtures_helpers.rb (renamed from spec/support/javascript_fixtures_helpers.rb)0
-rw-r--r--spec/support/helpers/jira_service_helper.rb (renamed from spec/support/jira_service_helper.rb)0
-rw-r--r--spec/support/helpers/kubernetes_helpers.rb (renamed from spec/support/kubernetes_helpers.rb)0
-rw-r--r--spec/support/helpers/ldap_helpers.rb (renamed from spec/support/ldap_helpers.rb)0
-rw-r--r--spec/support/helpers/live_debugger.rb (renamed from spec/support/live_debugger.rb)0
-rw-r--r--spec/support/helpers/login_helpers.rb (renamed from spec/support/login_helpers.rb)0
-rw-r--r--spec/support/helpers/markdown_feature.rb (renamed from spec/support/markdown_feature.rb)0
-rw-r--r--spec/support/helpers/merge_request_helpers.rb (renamed from spec/support/merge_request_helpers.rb)0
-rw-r--r--spec/support/helpers/migrations_helpers.rb (renamed from spec/support/migrations_helpers.rb)0
-rw-r--r--spec/support/helpers/mobile_helpers.rb (renamed from spec/support/mobile_helpers.rb)0
-rw-r--r--spec/support/helpers/project_forks_helper.rb (renamed from spec/support/project_forks_helper.rb)0
-rw-r--r--spec/support/helpers/prometheus_helpers.rb (renamed from spec/support/prometheus_helpers.rb)0
-rw-r--r--spec/support/helpers/query_recorder.rb38
-rw-r--r--spec/support/helpers/quick_actions_helpers.rb10
-rw-r--r--spec/support/helpers/rake_helpers.rb (renamed from spec/support/rake_helpers.rb)0
-rw-r--r--spec/support/helpers/reactive_caching_helpers.rb (renamed from spec/support/reactive_caching_helpers.rb)0
-rw-r--r--spec/support/helpers/redis_without_keys.rb (renamed from spec/support/redis_without_keys.rb)0
-rw-r--r--spec/support/helpers/reference_parser_helpers.rb (renamed from spec/support/reference_parser_helpers.rb)0
-rw-r--r--spec/support/helpers/repo_helpers.rb (renamed from spec/support/repo_helpers.rb)0
-rw-r--r--spec/support/helpers/search_helpers.rb (renamed from spec/support/search_helpers.rb)0
-rw-r--r--spec/support/helpers/seed_helper.rb (renamed from spec/support/seed_helper.rb)10
-rw-r--r--spec/support/helpers/seed_repo.rb (renamed from spec/support/seed_repo.rb)0
-rw-r--r--spec/support/helpers/select2_helper.rb (renamed from spec/support/select2_helper.rb)0
-rw-r--r--spec/support/helpers/selection_helper.rb (renamed from spec/support/selection_helper.rb)0
-rw-r--r--spec/support/helpers/sorting_helper.rb18
-rw-r--r--spec/support/helpers/stub_configuration.rb (renamed from spec/support/stub_configuration.rb)3
-rw-r--r--spec/support/helpers/stub_env.rb (renamed from spec/support/stub_env.rb)0
-rw-r--r--spec/support/helpers/stub_feature_flags.rb (renamed from spec/support/stub_feature_flags.rb)0
-rw-r--r--spec/support/helpers/stub_gitlab_calls.rb (renamed from spec/support/stub_gitlab_calls.rb)0
-rw-r--r--spec/support/helpers/stub_gitlab_data.rb (renamed from spec/support/stub_gitlab_data.rb)0
-rw-r--r--spec/support/helpers/stub_object_storage.rb (renamed from spec/support/stub_object_storage.rb)2
-rw-r--r--spec/support/helpers/test_env.rb (renamed from spec/support/test_env.rb)0
-rw-r--r--spec/support/helpers/upload_helpers.rb (renamed from spec/support/upload_helpers.rb)0
-rw-r--r--spec/support/helpers/user_activities_helpers.rb (renamed from spec/support/user_activities_helpers.rb)0
-rw-r--r--spec/support/helpers/wait_for_requests.rb (renamed from spec/support/wait_for_requests.rb)0
-rw-r--r--spec/support/helpers/workhorse_helpers.rb (renamed from spec/support/workhorse_helpers.rb)0
-rw-r--r--spec/support/json_response.rb (renamed from spec/support/json_response_helpers.rb)4
-rw-r--r--spec/support/matchers/background_migrations_matchers.rb (renamed from spec/support/background_migrations_matchers.rb)0
-rw-r--r--spec/support/matchers/exceed_query_limit.rb (renamed from spec/support/query_recorder.rb)39
-rwxr-xr-xspec/support/prepare-gitlab-git-test-for-commit2
-rw-r--r--spec/support/routing_helpers.rb3
-rw-r--r--spec/support/rspec.rb12
-rw-r--r--spec/support/seed.rb7
-rw-r--r--spec/support/shared_contexts/json_response_shared_context.rb3
-rw-r--r--spec/support/shared_contexts/services_shared_context.rb (renamed from spec/support/services_shared_context.rb)0
-rw-r--r--spec/support/shared_examples/chat_slash_commands_shared_examples.rb (renamed from spec/support/chat_slash_commands_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/email_format_shared_examples.rb (renamed from spec/support/email_format_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/gitlab_verify.rb (renamed from spec/support/gitlab_verify.rb)26
-rw-r--r--spec/support/shared_examples/group_members_shared_example.rb (renamed from spec/support/group_members_shared_example.rb)0
-rw-r--r--spec/support/shared_examples/issuable_shared_examples.rb (renamed from spec/support/issuable_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/issuables_list_metadata_shared_examples.rb (renamed from spec/support/issuables_list_metadata_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/issue_tracker_service_shared_example.rb (renamed from spec/support/issue_tracker_service_shared_example.rb)0
-rw-r--r--spec/support/shared_examples/ldap_shared_examples.rb (renamed from spec/support/ldap_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/legacy_path_redirect_shared_examples.rb (renamed from spec/support/legacy_path_redirect_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/malicious_regexp_shared_examples.rb (renamed from spec/support/malicious_regexp_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/mentionable_shared_examples.rb (renamed from spec/support/mentionable_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/milestone_tabs_examples.rb (renamed from spec/support/milestone_tabs_examples.rb)0
-rw-r--r--spec/support/shared_examples/notify_shared_examples.rb (renamed from spec/support/notify_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/reference_parser_shared_examples.rb (renamed from spec/support/reference_parser_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb (renamed from spec/support/slack_mattermost_notifications_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/snippet_visibility.rb (renamed from spec/support/snippet_visibility.rb)0
-rw-r--r--spec/support/shared_examples/snippets_shared_examples.rb (renamed from spec/support/snippets_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/taskable_shared_examples.rb (renamed from spec/support/taskable_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/time_tracking_shared_examples.rb (renamed from spec/support/time_tracking_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/unique_ip_check_shared_examples.rb (renamed from spec/support/unique_ip_check_shared_examples.rb)0
-rw-r--r--spec/support/shared_examples/update_invalid_issuable.rb (renamed from spec/support/update_invalid_issuable.rb)0
-rw-r--r--spec/support/shared_examples/updating_mentions_shared_examples.rb (renamed from spec/support/updating_mentions_shared_examples.rb)0
141 files changed, 478 insertions, 320 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index d443238b9e1..16b0b5c95e2 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -143,7 +143,7 @@ Lint/MissingCopEnableDirective:
Lint/NestedPercentLiteral:
Exclude:
- 'lib/gitlab/git/repository.rb'
- - 'spec/support/email_format_shared_examples.rb'
+ - 'spec/support/shared_examples/email_format_shared_examples.rb'
# Offense count: 1
Lint/ReturnInVoidContext:
@@ -195,8 +195,8 @@ Naming/HeredocDelimiterCase:
- 'spec/lib/gitlab/diff/parser_spec.rb'
- 'spec/lib/json_web_token/rsa_token_spec.rb'
- 'spec/models/commit_spec.rb'
- - 'spec/support/repo_helpers.rb'
- - 'spec/support/seed_repo.rb'
+ - 'spec/support/helpers/repo_helpers.rb'
+ - 'spec/support/helpers/seed_repo.rb'
# Offense count: 112
# Configuration parameters: Blacklist.
@@ -496,7 +496,7 @@ Style/EmptyLiteral:
- 'spec/lib/gitlab/request_context_spec.rb'
- 'spec/lib/gitlab/workhorse_spec.rb'
- 'spec/requests/api/jobs_spec.rb'
- - 'spec/support/chat_slash_commands_shared_examples.rb'
+ - 'spec/support/shared_examples/chat_slash_commands_shared_examples.rb'
# Offense count: 102
# Cop supports --auto-correct.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 02599907af7..29009010f0e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -26,7 +26,9 @@ _This notice should stay as the first item in the CONTRIBUTING.md file._
- [Type labels (~"feature proposal", ~bug, ~customer, etc.)](#type-labels-feature-proposal-bug-customer-etc)
- [Subject labels (~wiki, ~"container registry", ~ldap, ~api, etc.)](#subject-labels-wiki-container-registry-ldap-api-etc)
- [Team labels (~"CI/CD", ~Discussion, ~Edge, ~Platform, etc.)](#team-labels-cicd-discussion-edge-platform-etc)
- - [Priority labels (~Deliverable, ~Stretch, ~"Next Patch Release")](#priority-labels-deliverable-stretch-next-patch-release)
+ - [Milestone labels (~Deliverable, ~Stretch, ~"Next Patch Release")](#milestone-labels-deliverable-stretch-next-patch-release)
+ - [Priority labels (~Deliverable, ~Stretch, ~"Next Patch Release")](#bug-priority-labels-p1-p2-p3-etc)
+ - [Severity labels (~Deliverable, ~Stretch, ~"Next Patch Release")](#bug-severity-labels-s1-s2-s3-etc)
- [Label for community contributors (~"Accepting Merge Requests")](#label-for-community-contributors-accepting-merge-requests)
- [Implement design & UI elements](#implement-design-ui-elements)
- [Issue tracker](#issue-tracker)
@@ -127,6 +129,8 @@ Most issues will have labels for at least one of the following:
- Subject: ~wiki, ~"container registry", ~ldap, ~api, ~frontend, etc.
- Team: ~"CI/CD", ~Discussion, ~Edge, ~Platform, etc.
- Milestone: ~Deliverable, ~Stretch, ~"Next Patch Release"
+- Priority: ~P1, ~P2, ~P3, ~P4
+- Severity: ~S1, ~S2, ~S3, ~S4
All labels, their meaning and priority are defined on the
[labels page][labels-page].
@@ -210,7 +214,7 @@ This label documents the planned timeline & urgency which is used to measure aga
| Label | Meaning | Estimate time to fix | Guidance |
|-------|-----------------|------------------------------------------------------------------|----------|
-| ~P1 | Urgent Priority | The current release | |
+| ~P1 | Urgent Priority | The current release + potentially immediate hotfix to GitLab.com | |
| ~P2 | High Priority | The next release | |
| ~P3 | Medium Priority | Within the next 3 releases (approx one quarter) | |
| ~P4 | Low Priority | Anything outside the next 3 releases (approx beyond one quarter) | The issue is prominent but does not impact user workflow and a workaround is documented |
diff --git a/Gemfile.lock b/Gemfile.lock
index 745732f3537..1ba99df5e44 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -178,7 +178,7 @@ GEM
docile (1.1.5)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
- doorkeeper (4.3.1)
+ doorkeeper (4.3.2)
railties (>= 4.2)
doorkeeper-openid_connect (1.3.0)
doorkeeper (~> 4.3)
diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb
index 7677891b9ce..13246a774e3 100644
--- a/app/models/concerns/avatarable.rb
+++ b/app/models/concerns/avatarable.rb
@@ -31,12 +31,13 @@ module Avatarable
asset_host = ActionController::Base.asset_host
use_asset_host = asset_host.present?
+ use_authentication = respond_to?(:public?) && !public?
# Avatars for private and internal groups and projects require authentication to be viewed,
# which means they can only be served by Rails, on the regular GitLab host.
# If an asset host is configured, we need to return the fully qualified URL
# instead of only the avatar path, so that Rails doesn't prefix it with the asset host.
- if use_asset_host && respond_to?(:public?) && !public?
+ if use_asset_host && use_authentication
use_asset_host = false
only_path = false
end
@@ -49,6 +50,6 @@ module Avatarable
url_base << gitlab_config.relative_url_root
end
- url_base + avatar.url
+ url_base + avatar.local_url
end
end
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb
index dfd7d94450b..915ad6959be 100644
--- a/app/models/concerns/routable.rb
+++ b/app/models/concerns/routable.rb
@@ -102,7 +102,7 @@ module Routable
# the route. Caching this per request ensures that even if we have multiple instances,
# we will not have to duplicate work, avoiding N+1 queries in some cases.
def full_path
- return uncached_full_path unless RequestStore.active?
+ return uncached_full_path unless RequestStore.active? && persisted?
RequestStore[full_path_key] ||= uncached_full_path
end
@@ -124,6 +124,11 @@ module Routable
end
end
+ # Group would override this to check from association
+ def owned_by?(user)
+ owner == user
+ end
+
private
def set_path_errors
diff --git a/app/models/group.rb b/app/models/group.rb
index 8ff781059cc..9b42bbf99be 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -125,6 +125,10 @@ class Group < Namespace
self[:lfs_enabled]
end
+ def owned_by?(user)
+ owners.include?(user)
+ end
+
def add_users(users, access_level, current_user: nil, expires_at: nil)
GroupMember.add_users(
self,
diff --git a/app/uploaders/gitlab_uploader.rb b/app/uploaders/gitlab_uploader.rb
index f12f0466a1d..f8a237178d9 100644
--- a/app/uploaders/gitlab_uploader.rb
+++ b/app/uploaders/gitlab_uploader.rb
@@ -65,6 +65,10 @@ class GitlabUploader < CarrierWave::Uploader::Base
!!model
end
+ def local_url
+ File.join('/', self.class.base_dir, dynamic_segment, filename)
+ end
+
private
# Designed to be overridden by child uploaders that have a dynamic path
diff --git a/app/views/admin/application_settings/_repository_storage.html.haml b/app/views/admin/application_settings/_repository_storage.html.haml
index ac31977e1a9..4eebb59110a 100644
--- a/app/views/admin/application_settings/_repository_storage.html.haml
+++ b/app/views/admin/application_settings/_repository_storage.html.haml
@@ -21,7 +21,7 @@
.help-block
Manage repository storage paths. Learn more in the
= succeed "." do
- = link_to "repository storages documentation", help_page_path("administration/repository_storages")
+ = link_to "repository storages documentation", help_page_path("administration/repository_storage_paths")
.sub-section
%h4 Circuit breaker
.form-group
diff --git a/changelogs/unreleased/42936-improve-ns-factory-avoid-duplicates.yml b/changelogs/unreleased/42936-improve-ns-factory-avoid-duplicates.yml
new file mode 100644
index 00000000000..54b523b65a1
--- /dev/null
+++ b/changelogs/unreleased/42936-improve-ns-factory-avoid-duplicates.yml
@@ -0,0 +1,6 @@
+---
+title: Fix discussions API setting created_at for notable in a group or notable in
+ a project in a group with owners
+merge_request: 18464
+author:
+type: fixed
diff --git a/changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml b/changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml
new file mode 100644
index 00000000000..80b5b4a8abe
--- /dev/null
+++ b/changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml
@@ -0,0 +1,5 @@
+---
+title: Fixed wrong avatar URL when the avatar is on object storage.
+merge_request: 18092
+author:
+type: fixed
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb
index dc7999ac556..9b00ae459a3 100644
--- a/config/initializers/1_settings.rb
+++ b/config/initializers/1_settings.rb
@@ -1,131 +1,4 @@
-# rubocop:disable GitlabSecurity/PublicSend
-
-require_dependency Rails.root.join('lib/gitlab') # Load Gitlab as soon as possible
-
-class Settings < Settingslogic
- source ENV.fetch('GITLAB_CONFIG') { "#{Rails.root}/config/gitlab.yml" }
- namespace Rails.env
-
- class << self
- def gitlab_on_standard_port?
- on_standard_port?(gitlab)
- end
-
- def host_without_www(url)
- host(url).sub('www.', '')
- end
-
- def build_gitlab_ci_url
- custom_port =
- if on_standard_port?(gitlab)
- nil
- else
- ":#{gitlab.port}"
- end
-
- [
- gitlab.protocol,
- "://",
- gitlab.host,
- custom_port,
- gitlab.relative_url_root
- ].join('')
- end
-
- def build_pages_url
- base_url(pages).join('')
- end
-
- def build_gitlab_shell_ssh_path_prefix
- user_host = "#{gitlab_shell.ssh_user}@#{gitlab_shell.ssh_host}"
-
- if gitlab_shell.ssh_port != 22
- "ssh://#{user_host}:#{gitlab_shell.ssh_port}/"
- else
- if gitlab_shell.ssh_host.include? ':'
- "[#{user_host}]:"
- else
- "#{user_host}:"
- end
- end
- end
-
- def build_base_gitlab_url
- base_url(gitlab).join('')
- end
-
- def build_gitlab_url
- (base_url(gitlab) + [gitlab.relative_url_root]).join('')
- end
-
- # check that values in `current` (string or integer) is a contant in `modul`.
- def verify_constant_array(modul, current, default)
- values = default || []
- unless current.nil?
- values = []
- current.each do |constant|
- values.push(verify_constant(modul, constant, nil))
- end
- values.delete_if { |value| value.nil? }
- end
-
- values
- end
-
- # check that `current` (string or integer) is a contant in `modul`.
- def verify_constant(modul, current, default)
- constant = modul.constants.find { |name| modul.const_get(name) == current }
- value = constant.nil? ? default : modul.const_get(constant)
- if current.is_a? String
- value = modul.const_get(current.upcase) rescue default
- end
-
- value
- end
-
- def absolute(path)
- File.expand_path(path, Rails.root)
- end
-
- private
-
- def base_url(config)
- custom_port = on_standard_port?(config) ? nil : ":#{config.port}"
-
- [
- config.protocol,
- "://",
- config.host,
- custom_port
- ]
- end
-
- def on_standard_port?(config)
- config.port.to_i == (config.https ? 443 : 80)
- end
-
- # Extract the host part of the given +url+.
- def host(url)
- url = url.downcase
- url = "http://#{url}" unless url.start_with?('http')
-
- # Get rid of the path so that we don't even have to encode it
- url_without_path = url.sub(%r{(https?://[^/]+)/?.*}, '\1')
-
- URI.parse(url_without_path).host
- end
-
- # Runs every minute in a random ten-minute period on Sundays, to balance the
- # load on the server receiving these pings. The usage ping is safe to run
- # multiple times because of a 24 hour exclusive lock.
- def cron_for_usage_ping
- hour = rand(24)
- minute = rand(6)
-
- "#{minute}0-#{minute}9 #{hour} * * 0"
- end
- end
-end
+require_dependency File.expand_path('../../lib/gitlab', __dir__) # Load Gitlab as soon as possible
# Default settings
Settings['ldap'] ||= Settingslogic.new({})
diff --git a/config/initializers/2_app.rb b/config/initializers/2_app.rb
deleted file mode 100644
index bd74f90e7d2..00000000000
--- a/config/initializers/2_app.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-module Gitlab
- def self.config
- Settings
- end
-
- VERSION = File.read(Rails.root.join("VERSION")).strip.freeze
- REVISION = Gitlab::Popen.popen(%W(#{config.git.bin_path} log --pretty=format:%h -n 1)).first.chomp.freeze
-end
diff --git a/db/fixtures/development/17_cycle_analytics.rb b/db/fixtures/development/17_cycle_analytics.rb
index d7be6f5950f..7b9a4bad449 100644
--- a/db/fixtures/development/17_cycle_analytics.rb
+++ b/db/fixtures/development/17_cycle_analytics.rb
@@ -1,5 +1,5 @@
require './spec/support/sidekiq'
-require './spec/support/test_env'
+require './spec/support/helpers/test_env'
class Gitlab::Seeder::CycleAnalytics
def initialize(project, perf: false)
diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md
index df80cd9f584..b77e9b7ff63 100644
--- a/doc/development/testing_guide/best_practices.md
+++ b/doc/development/testing_guide/best_practices.md
@@ -90,6 +90,25 @@ Finished in 34.51 seconds (files took 0.76702 seconds to load)
Note: `live_debug` only works on javascript enabled specs.
+### Fast unit tests
+
+Some classes are well-isolated from Rails and you should be able to test them
+without the overhead added by the Rails environment and Bundler's `:default`
+group's gem loading. In these cases, you can `require 'fast_spec_helper'`
+instead of `require 'spec_helper'` in your test file, and your test should run
+really fast since:
+
+- Gems loading is skipped
+- Rails app boot is skipped
+- gitlab-shell and Gitaly setup are skipped
+- Test repositories setup are skipped
+
+Note that in some cases, you might have to add some `require_dependency 'foo'`
+in your file under test since Rails autoloading is not available in these cases.
+
+This shouldn't be a problem since explicitely listing dependencies should be
+considered a good practice anyway.
+
### `let` variables
GitLab's RSpec suite has made extensive use of `let` variables to reduce
@@ -281,14 +300,13 @@ All fixtures should be be placed under `spec/fixtures/`.
RSpec config files are files that change the RSpec config (i.e.
`RSpec.configure do |config|` blocks). They should be placed under
-`spec/support/config/`.
+`spec/support/`.
Each file should be related to a specific domain, e.g.
-`spec/support/config/capybara.rb`, `spec/support/config/carrierwave.rb`, etc.
+`spec/support/capybara.rb`, `spec/support/carrierwave.rb`, etc.
-Helpers can be included in the `spec/support/config/rspec.rb` file. If a
-helpers module applies only to a certain kind of specs, it should add modifiers
-to the `config.include` call. For instance if
+If a helpers module applies only to a certain kind of specs, it should add
+modifiers to the `config.include` call. For instance if
`spec/support/helpers/cycle_analytics_helpers.rb` applies to `:lib` and
`type: :model` specs only, you would write the following:
@@ -299,6 +317,14 @@ RSpec.configure do |config|
end
```
+If a config file only consists of `config.include`, you can add these
+`config.include` directly in `spec/spec_helper.rb`.
+
+For very generic helpers, consider including them in the `spec/support/rspec.rb`
+file which is used by the `spec/fast_spec_helper.rb` file. See
+[Fast unit tests](#fast-unit-tests) for more details about the
+`spec/fast_spec_helper.rb` file.
+
---
[Return to Testing documentation](index.md)
diff --git a/doc/development/testing_guide/testing_rake_tasks.md b/doc/development/testing_guide/testing_rake_tasks.md
index 60163f1a230..db8ca87e9f8 100644
--- a/doc/development/testing_guide/testing_rake_tasks.md
+++ b/doc/development/testing_guide/testing_rake_tasks.md
@@ -9,7 +9,7 @@ At a minimum, requiring the Rake helper will redirect `stdout`, include the
runtime task helpers, and include the `RakeHelpers` Spec support module.
The `RakeHelpers` module exposes a `run_rake_task(<task>)` method to make
-executing tasks simple. See `spec/support/rake_helpers.rb` for all available
+executing tasks simple. See `spec/support/helpers/rake_helpers.rb` for all available
methods.
Example:
diff --git a/doc/user/project/deploy_tokens/index.md b/doc/user/project/deploy_tokens/index.md
index 86fc58020e8..34154b69d2d 100644
--- a/doc/user/project/deploy_tokens/index.md
+++ b/doc/user/project/deploy_tokens/index.md
@@ -23,7 +23,7 @@ You can create as many deploy tokens as you like from the settings of your proje
![Personal access tokens page](img/deploy_tokens.png)
-## Revoking a personal access token
+## Revoking a deploy token
At any time, you can revoke any deploy token by just clicking the
respective **Revoke** button under the 'Active deploy tokens' area.
diff --git a/features/support/env.rb b/features/support/env.rb
index 15211995918..8fa2fcb6e3e 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -12,7 +12,11 @@ end
WebMock.enable!
-%w(select2_helper test_env repo_helpers wait_for_requests sidekiq project_forks_helper webmock).each do |f|
+%w(select2_helper test_env repo_helpers wait_for_requests project_forks_helper).each do |f|
+ require Rails.root.join('spec', 'support', 'helpers', f)
+end
+
+%w(sidekiq webmock).each do |f|
require Rails.root.join('spec', 'support', f)
end
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index cd91df1ecd8..b74b8149834 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -64,8 +64,10 @@ module API
authorize! :create_note, noteable
parent = noteable_parent(noteable)
+
if opts[:created_at]
- opts.delete(:created_at) unless current_user.admin? || parent.owner == current_user
+ opts.delete(:created_at) unless
+ current_user.admin? || parent.owned_by?(current_user)
end
project = parent if parent.is_a?(Project)
diff --git a/lib/gitlab.rb b/lib/gitlab.rb
index f6629982512..0a167104bf4 100644
--- a/lib/gitlab.rb
+++ b/lib/gitlab.rb
@@ -1,9 +1,20 @@
-require_dependency 'gitlab/git'
+require_dependency 'settings'
+require_dependency 'gitlab/popen'
module Gitlab
+ def self.root
+ Pathname.new(File.expand_path('..', __dir__))
+ end
+
+ def self.config
+ Settings
+ end
+
COM_URL = 'https://gitlab.com'.freeze
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}
+ VERSION = File.read(root.join("VERSION")).strip.freeze
+ REVISION = Gitlab::Popen.popen(%W(#{config.git.bin_path} log --pretty=format:%h -n 1)).first.chomp.freeze
def self.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
diff --git a/lib/gitlab/git.rb b/lib/gitlab/git.rb
index c9abea90d21..e85e87a54af 100644
--- a/lib/gitlab/git.rb
+++ b/lib/gitlab/git.rb
@@ -1,3 +1,5 @@
+require_dependency 'gitlab/encoding_helper'
+
module Gitlab
module Git
# The ID of empty tree.
diff --git a/lib/settings.rb b/lib/settings.rb
new file mode 100644
index 00000000000..69d637761ea
--- /dev/null
+++ b/lib/settings.rb
@@ -0,0 +1,126 @@
+require 'settingslogic'
+
+class Settings < Settingslogic
+ source ENV.fetch('GITLAB_CONFIG') { Pathname.new(File.expand_path('..', __dir__)).join('config/gitlab.yml') }
+ namespace ENV.fetch('GITLAB_ENV') { Rails.env }
+
+ class << self
+ def gitlab_on_standard_port?
+ on_standard_port?(gitlab)
+ end
+
+ def host_without_www(url)
+ host(url).sub('www.', '')
+ end
+
+ def build_gitlab_ci_url
+ custom_port =
+ if on_standard_port?(gitlab)
+ nil
+ else
+ ":#{gitlab.port}"
+ end
+
+ [
+ gitlab.protocol,
+ "://",
+ gitlab.host,
+ custom_port,
+ gitlab.relative_url_root
+ ].join('')
+ end
+
+ def build_pages_url
+ base_url(pages).join('')
+ end
+
+ def build_gitlab_shell_ssh_path_prefix
+ user_host = "#{gitlab_shell.ssh_user}@#{gitlab_shell.ssh_host}"
+
+ if gitlab_shell.ssh_port != 22
+ "ssh://#{user_host}:#{gitlab_shell.ssh_port}/"
+ else
+ if gitlab_shell.ssh_host.include? ':'
+ "[#{user_host}]:"
+ else
+ "#{user_host}:"
+ end
+ end
+ end
+
+ def build_base_gitlab_url
+ base_url(gitlab).join('')
+ end
+
+ def build_gitlab_url
+ (base_url(gitlab) + [gitlab.relative_url_root]).join('')
+ end
+
+ # check that values in `current` (string or integer) is a contant in `modul`.
+ def verify_constant_array(modul, current, default)
+ values = default || []
+ unless current.nil?
+ values = []
+ current.each do |constant|
+ values.push(verify_constant(modul, constant, nil))
+ end
+ values.delete_if { |value| value.nil? }
+ end
+
+ values
+ end
+
+ # check that `current` (string or integer) is a contant in `modul`.
+ def verify_constant(modul, current, default)
+ constant = modul.constants.find { |name| modul.const_get(name) == current }
+ value = constant.nil? ? default : modul.const_get(constant)
+ if current.is_a? String
+ value = modul.const_get(current.upcase) rescue default
+ end
+
+ value
+ end
+
+ def absolute(path)
+ File.expand_path(path, Rails.root)
+ end
+
+ private
+
+ def base_url(config)
+ custom_port = on_standard_port?(config) ? nil : ":#{config.port}"
+
+ [
+ config.protocol,
+ "://",
+ config.host,
+ custom_port
+ ]
+ end
+
+ def on_standard_port?(config)
+ config.port.to_i == (config.https ? 443 : 80)
+ end
+
+ # Extract the host part of the given +url+.
+ def host(url)
+ url = url.downcase
+ url = "http://#{url}" unless url.start_with?('http')
+
+ # Get rid of the path so that we don't even have to encode it
+ url_without_path = url.sub(%r{(https?://[^/]+)/?.*}, '\1')
+
+ URI.parse(url_without_path).host
+ end
+
+ # Runs every minute in a random ten-minute period on Sundays, to balance the
+ # load on the server receiving these pings. The usage ping is safe to run
+ # multiple times because of a 24 hour exclusive lock.
+ def cron_for_usage_ping
+ hour = rand(24)
+ minute = rand(6)
+
+ "#{minute}0-#{minute}9 #{hour} * * 0"
+ end
+ end
+end
diff --git a/rubocop/spec_helpers.rb b/rubocop/spec_helpers.rb
index 6c0f0193b1a..9bf5f1e3b18 100644
--- a/rubocop/spec_helpers.rb
+++ b/rubocop/spec_helpers.rb
@@ -1,6 +1,6 @@
module RuboCop
module SpecHelpers
- SPEC_HELPERS = %w[spec_helper.rb rails_helper.rb].freeze
+ SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze
# Returns true if the given node originated from the spec directory.
def in_spec?(node)
diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb
index 2be46049aab..be49b92d23f 100644
--- a/spec/controllers/import/bitbucket_controller_spec.rb
+++ b/spec/controllers/import/bitbucket_controller_spec.rb
@@ -223,11 +223,12 @@ describe Import::BitbucketController do
end
context 'user has chosen an existing nested namespace and name for the project', :postgresql do
- let(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let(:parent_namespace) { create(:group, name: 'foo') }
let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) }
let(:test_name) { 'test_name' }
before do
+ parent_namespace.add_owner(user)
nested_namespace.add_owner(user)
end
@@ -273,7 +274,7 @@ describe Import::BitbucketController do
context 'user has chosen existent and non-existent nested namespaces and name for the project', :postgresql do
let(:test_name) { 'test_name' }
- let!(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let!(:parent_namespace) { create(:group, name: 'foo') }
before do
parent_namespace.add_owner(user)
diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb
index e958be077c2..742f4787126 100644
--- a/spec/controllers/import/gitlab_controller_spec.rb
+++ b/spec/controllers/import/gitlab_controller_spec.rb
@@ -196,10 +196,11 @@ describe Import::GitlabController do
end
context 'user has chosen an existing nested namespace for the project', :postgresql do
- let(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let(:parent_namespace) { create(:group, name: 'foo') }
let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) }
before do
+ parent_namespace.add_owner(user)
nested_namespace.add_owner(user)
end
@@ -245,7 +246,7 @@ describe Import::GitlabController do
context 'user has chosen existent and non-existent nested namespaces and name for the project', :postgresql do
let(:test_name) { 'test_name' }
- let!(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let!(:parent_namespace) { create(:group, name: 'foo') }
before do
parent_namespace.add_owner(user)
diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb
index c4b32dc3a09..e20623c0ac1 100644
--- a/spec/controllers/projects/forks_controller_spec.rb
+++ b/spec/controllers/projects/forks_controller_spec.rb
@@ -4,7 +4,11 @@ describe Projects::ForksController do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:forked_project) { Projects::ForkService.new(project, user).execute }
- let(:group) { create(:group, owner: forked_project.creator) }
+ let(:group) { create(:group) }
+
+ before do
+ group.add_owner(user)
+ end
describe 'GET index' do
def get_forks
diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb
index d5d819d862a..818f7b046f6 100644
--- a/spec/factories/commits.rb
+++ b/spec/factories/commits.rb
@@ -1,4 +1,4 @@
-require_relative '../support/repo_helpers'
+require_relative '../support/helpers/repo_helpers'
FactoryBot.define do
factory :commit do
diff --git a/spec/factories/gpg_key_subkeys.rb b/spec/factories/gpg_key_subkeys.rb
index 57eaaee345f..6c7db5379a9 100644
--- a/spec/factories/gpg_key_subkeys.rb
+++ b/spec/factories/gpg_key_subkeys.rb
@@ -1,5 +1,3 @@
-require_relative '../support/gpg_helpers'
-
FactoryBot.define do
factory :gpg_key_subkey do
gpg_key
diff --git a/spec/factories/gpg_keys.rb b/spec/factories/gpg_keys.rb
index b8aabf74221..51b8ddc9934 100644
--- a/spec/factories/gpg_keys.rb
+++ b/spec/factories/gpg_keys.rb
@@ -1,4 +1,4 @@
-require_relative '../support/gpg_helpers'
+require_relative '../support/helpers/gpg_helpers'
FactoryBot.define do
factory :gpg_key do
diff --git a/spec/factories/gpg_signature.rb b/spec/factories/gpg_signature.rb
index 4620caff823..b89e6ffc4b3 100644
--- a/spec/factories/gpg_signature.rb
+++ b/spec/factories/gpg_signature.rb
@@ -1,5 +1,3 @@
-require_relative '../support/gpg_helpers'
-
FactoryBot.define do
factory :gpg_signature do
commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) }
diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb
index 8c531cf5909..3b354c0d96b 100644
--- a/spec/factories/groups.rb
+++ b/spec/factories/groups.rb
@@ -5,6 +5,14 @@ FactoryBot.define do
type 'Group'
owner nil
+ after(:create) do |group|
+ if group.owner
+ # We could remove this after we have proper constraint:
+ # https://gitlab.com/gitlab-org/gitlab-ce/issues/43292
+ raise "Don't set owner for groups, use `group.add_owner(user)` instead"
+ end
+ end
+
trait :public do
visibility_level Gitlab::VisibilityLevel::PUBLIC
end
diff --git a/spec/factories/namespaces.rb b/spec/factories/namespaces.rb
index f94b09cff15..6feafa5ece9 100644
--- a/spec/factories/namespaces.rb
+++ b/spec/factories/namespaces.rb
@@ -2,6 +2,22 @@ FactoryBot.define do
factory :namespace do
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
- owner
+
+ # This is a workaround to avoid the user creating another namespace via
+ # User#ensure_namespace_correct. We should try to remove it and then
+ # we could remove this workaround
+ association :owner, factory: :user, strategy: :build
+ before(:create) do |namespace|
+ owner = namespace.owner
+
+ if owner
+ # We're changing the username here because we want to keep our path,
+ # and User#ensure_namespace_correct would change the path based on
+ # username, so we're forced to do this otherwise we'll need to change
+ # a lot of existing tests.
+ owner.username = namespace.path
+ owner.namespace = namespace
+ end
+ end
end
end
diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb
index 857333f222d..40f3fa7d69b 100644
--- a/spec/factories/notes.rb
+++ b/spec/factories/notes.rb
@@ -1,4 +1,4 @@
-require_relative '../support/repo_helpers'
+require_relative '../support/helpers/repo_helpers'
include ActionDispatch::TestProcess
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index 1761b6e2a3b..1ae6152a1f0 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -1,4 +1,4 @@
-require_relative '../support/test_env'
+require_relative '../support/helpers/test_env'
FactoryBot.define do
# Project without repository
diff --git a/spec/fast_spec_helper.rb b/spec/fast_spec_helper.rb
new file mode 100644
index 00000000000..f28268b0754
--- /dev/null
+++ b/spec/fast_spec_helper.rb
@@ -0,0 +1,15 @@
+require 'bundler/setup'
+
+ENV['GITLAB_ENV'] = 'test'
+ENV['IN_MEMORY_APPLICATION_SETTINGS'] = 'true'
+
+unless Object.respond_to?(:require_dependency)
+ class Object
+ alias_method :require_dependency, :require
+ end
+end
+
+# Defines Gitlab and Gitlab.config which are at the center of the app
+require_relative '../lib/gitlab' unless defined?(Gitlab.config)
+
+require_relative 'support/rspec'
diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb
index a5954fec54b..fee6287558e 100644
--- a/spec/features/projects/new_project_spec.rb
+++ b/spec/features/projects/new_project_spec.rb
@@ -64,7 +64,7 @@ feature 'New project' do
end
context 'with group namespace' do
- let(:group) { create(:group, :private, owner: user) }
+ let(:group) { create(:group, :private) }
before do
group.add_owner(user)
@@ -81,7 +81,7 @@ feature 'New project' do
end
context 'with subgroup namespace' do
- let(:group) { create(:group, owner: user) }
+ let(:group) { create(:group) }
let(:subgroup) { create(:group, parent: group) }
before do
diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
index ae5b31dc12d..c3f528dd6fc 100644
--- a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
@@ -15,7 +15,7 @@ describe Gitlab::BitbucketImport::ProjectCreator do
has_wiki?: false)
end
- let(:namespace) { create(:group, owner: user) }
+ let(:namespace) { create(:group) }
let(:token) { "asdasd12345" }
let(:secret) { "sekrettt" }
let(:access_params) { { bitbucket_access_token: token, bitbucket_access_token_secret: secret } }
diff --git a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb
index 82548c7fd31..5ea086e4abd 100644
--- a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb
@@ -12,7 +12,7 @@ describe Gitlab::GitlabImport::ProjectCreator do
owner: { name: "john" }
}.with_indifferent_access
end
- let(:namespace) { create(:group, owner: user) }
+ let(:namespace) { create(:group) }
let(:token) { "asdffg" }
let(:access_params) { { gitlab_access_token: token } }
diff --git a/spec/lib/gitlab/google_code_import/project_creator_spec.rb b/spec/lib/gitlab/google_code_import/project_creator_spec.rb
index 8d5b60d50de..24cd518c77b 100644
--- a/spec/lib/gitlab/google_code_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/google_code_import/project_creator_spec.rb
@@ -9,7 +9,7 @@ describe Gitlab::GoogleCodeImport::ProjectCreator do
"repositoryUrls" => ["https://vim.googlecode.com/git/"]
)
end
- let(:namespace) { create(:group, owner: user) }
+ let(:namespace) { create(:group) }
before do
namespace.add_owner(user)
diff --git a/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb b/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
index 737c9a624e0..eb1b13704ea 100644
--- a/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::LegacyGithubImport::ProjectCreator do
let(:user) { create(:user) }
- let(:namespace) { create(:group, owner: user) }
+ let(:namespace) { create(:group) }
let(:repo) do
OpenStruct.new(
diff --git a/spec/lib/gitlab_spec.rb b/spec/lib/gitlab_spec.rb
index bd443a5d9e7..da146e24893 100644
--- a/spec/lib/gitlab_spec.rb
+++ b/spec/lib/gitlab_spec.rb
@@ -1,6 +1,14 @@
-require 'rails_helper'
+require 'fast_spec_helper'
+
+require_dependency 'gitlab'
describe Gitlab do
+ describe '.root' do
+ it 'returns the root path of the app' do
+ expect(described_class.root).to eq(Pathname.new(File.expand_path('../..', __dir__)))
+ end
+ end
+
describe '.com?' do
it 'is true when on GitLab.com' do
stub_config_setting(url: 'https://gitlab.com')
diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb
index 3696e6f62fd..9faf21bfbbd 100644
--- a/spec/models/concerns/avatarable_spec.rb
+++ b/spec/models/concerns/avatarable_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Avatarable do
- set(:project) { create(:project, avatar: fixture_file_upload(File.join(Rails.root, 'spec/fixtures/dk.png'))) }
+ let(:project) { create(:project, :with_avatar) }
let(:gitlab_host) { "https://gitlab.example.com" }
let(:relative_url_root) { "/gitlab" }
@@ -37,11 +37,23 @@ describe Avatarable do
project.visibility_level = visibility_level
end
- let(:avatar_path) { (avatar_path_prefix + [project.avatar.url]).join }
+ let(:avatar_path) { (avatar_path_prefix + [project.avatar.local_url]).join }
it 'returns the expected avatar path' do
expect(project.avatar_path(only_path: only_path)).to eq(avatar_path)
end
+
+ context "when avatar is stored remotely" do
+ before do
+ stub_uploads_object_storage(AvatarUploader)
+
+ project.avatar.migrate!(ObjectStorage::Store::REMOTE)
+ end
+
+ it 'returns the expected avatar path' do
+ expect(project.avatar_url(only_path: only_path)).to eq(avatar_path)
+ end
+ end
end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 2675c2f52c1..4002722e358 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -325,7 +325,7 @@ describe Project do
let(:owner) { create(:user, name: 'Gitlab') }
let(:namespace) { create(:namespace, path: 'sample-namespace', owner: owner) }
let(:project) { create(:project, path: 'sample-project', namespace: namespace) }
- let(:group) { create(:group, name: 'Group', path: 'sample-group', owner: owner) }
+ let(:group) { create(:group, name: 'Group', path: 'sample-group') }
context 'when nil argument' do
it 'returns nil' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 35db7616efb..3f2eb58f009 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1164,8 +1164,12 @@ describe User do
end
context 'with a group route matching the given path' do
+ let!(:group) { create(:group, path: 'group_path') }
+
context 'when the group namespace has an owner_id (legacy data)' do
- let!(:group) { create(:group, path: 'group_path', owner: user) }
+ before do
+ group.update!(owner_id: user.id)
+ end
it 'returns nil' do
expect(described_class.find_by_full_path('group_path')).to eq(nil)
@@ -1173,8 +1177,6 @@ describe User do
end
context 'when the group namespace does not have an owner_id' do
- let!(:group) { create(:group, path: 'group_path') }
-
it 'returns nil' do
expect(described_class.find_by_full_path('group_path')).to eq(nil)
end
diff --git a/spec/services/groups/nested_create_service_spec.rb b/spec/services/groups/nested_create_service_spec.rb
index 6491fb34777..86fdd43c1e5 100644
--- a/spec/services/groups/nested_create_service_spec.rb
+++ b/spec/services/groups/nested_create_service_spec.rb
@@ -59,8 +59,11 @@ describe Groups::NestedCreateService do
describe "#execute" do
it 'returns the group if it already existed' do
- parent = create(:group, path: 'a-group', owner: user)
- child = create(:group, path: 'a-sub-group', parent: parent, owner: user)
+ parent = create(:group, path: 'a-group')
+ child = create(:group, path: 'a-sub-group', parent: parent)
+
+ parent.add_owner(user)
+ child.add_owner(user)
expect(service.execute).to eq(child)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 83664bae046..53045815a6a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -32,42 +32,19 @@ require 'rainbow/ext/string'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
+# Requires helpers, and shared contexts/examples first since they're used in other support files
+Dir[Rails.root.join("spec/support/helpers/*.rb")].each { |f| require f }
+Dir[Rails.root.join("spec/support/shared_contexts/*.rb")].each { |f| require f }
+Dir[Rails.root.join("spec/support/shared_examples/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.use_instantiated_fixtures = false
- config.mock_with :rspec
config.verbose_retry = true
config.display_try_failure_messages = true
- config.include Devise::Test::ControllerHelpers, type: :controller
- config.include Devise::Test::ControllerHelpers, type: :view
- config.include Devise::Test::IntegrationHelpers, type: :feature
- config.include Warden::Test::Helpers, type: :request
- config.include LoginHelpers, type: :feature
- config.include SearchHelpers, type: :feature
- config.include CookieHelper, :js
- config.include InputHelper, :js
- config.include SelectionHelper, :js
- config.include InspectRequests, :js
- config.include WaitForRequests, :js
- config.include LiveDebugger, :js
- config.include StubConfiguration
- config.include EmailHelpers, :mailer, type: :mailer
- config.include TestEnv
- config.include ActiveJob::TestHelper
- config.include ActiveSupport::Testing::TimeHelpers
- config.include StubGitlabCalls
- config.include StubGitlabData
- config.include ApiHelpers, :api
- config.include Gitlab::Routing, type: :routing
- config.include MigrationsHelpers, :migration
- config.include StubFeatureFlags
- config.include StubENV
- config.include ExpectOffense
-
config.infer_spec_type_from_file_location!
config.define_derived_metadata(file_path: %r{/spec/}) do |metadata|
@@ -82,7 +59,33 @@ RSpec.configure do |config|
metadata[:type] = match[1].singularize.to_sym if match
end
- config.raise_errors_for_deprecations!
+ config.include ActiveJob::TestHelper
+ config.include ActiveSupport::Testing::TimeHelpers
+ config.include CycleAnalyticsHelpers
+ config.include ExpectOffense
+ config.include FactoryBot::Syntax::Methods
+ config.include FixtureHelpers
+ config.include GitlabRoutingHelper
+ config.include StubFeatureFlags
+ config.include StubGitlabCalls
+ config.include StubGitlabData
+ config.include TestEnv
+ config.include Devise::Test::ControllerHelpers, type: :controller
+ config.include Devise::Test::IntegrationHelpers, type: :feature
+ config.include LoginHelpers, type: :feature
+ config.include SearchHelpers, type: :feature
+ config.include EmailHelpers, :mailer, type: :mailer
+ config.include Warden::Test::Helpers, type: :request
+ config.include Gitlab::Routing, type: :routing
+ config.include Devise::Test::ControllerHelpers, type: :view
+ config.include ApiHelpers, :api
+ config.include CookieHelper, :js
+ config.include InputHelper, :js
+ config.include SelectionHelper, :js
+ config.include InspectRequests, :js
+ config.include WaitForRequests, :js
+ config.include LiveDebugger, :js
+ config.include MigrationsHelpers, :migration
if ENV['CI']
# This includes the first try, i.e. tests will be run 4 times before failing.
diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb
index 9ddcc5f2fbf..c0ceb0f6605 100644
--- a/spec/support/capybara.rb
+++ b/spec/support/capybara.rb
@@ -60,6 +60,8 @@ Capybara::Screenshot.register_driver(:chrome) do |driver, path|
end
RSpec.configure do |config|
+ config.include CapybaraHelpers, type: :feature
+
config.before(:context, :js) do
next if $capybara_server_already_started
diff --git a/spec/support/controllers/githubish_import_controller_shared_examples.rb b/spec/support/controllers/githubish_import_controller_shared_examples.rb
index 3321f920666..368439aa5b0 100644
--- a/spec/support/controllers/githubish_import_controller_shared_examples.rb
+++ b/spec/support/controllers/githubish_import_controller_shared_examples.rb
@@ -56,7 +56,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
end
it "assigns variables" do
- project = create(:project, import_type: provider, creator_id: user.id)
+ project = create(:project, import_type: provider, namespace: user.namespace)
stub_client(repos: [repo, org_repo], orgs: [org], org_repos: [org_repo])
get :status
@@ -69,7 +69,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
end
it "does not show already added project" do
- project = create(:project, import_type: provider, creator_id: user.id, import_source: 'asd/vim')
+ project = create(:project, import_type: provider, namespace: user.namespace, import_source: 'asd/vim')
stub_client(repos: [repo], orgs: [])
get :status
@@ -257,11 +257,12 @@ shared_examples 'a GitHub-ish import controller: POST create' do
end
context 'user has chosen an existing nested namespace and name for the project', :postgresql do
- let(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let(:parent_namespace) { create(:group, name: 'foo') }
let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) }
let(:test_name) { 'test_name' }
before do
+ parent_namespace.add_owner(user)
nested_namespace.add_owner(user)
end
@@ -307,7 +308,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do
context 'user has chosen existent and non-existent nested namespaces and name for the project', :postgresql do
let(:test_name) { 'test_name' }
- let!(:parent_namespace) { create(:group, name: 'foo', owner: user) }
+ let!(:parent_namespace) { create(:group, name: 'foo') }
before do
parent_namespace.add_owner(user)
diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb
deleted file mode 100644
index c7890e49c66..00000000000
--- a/spec/support/factory_bot.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-RSpec.configure do |config|
- config.include FactoryBot::Syntax::Methods
-end
diff --git a/spec/support/generate-seed-repo-rb b/spec/support/generate-seed-repo-rb
index 876b3b8242d..44b3de23b99 100755
--- a/spec/support/generate-seed-repo-rb
+++ b/spec/support/generate-seed-repo-rb
@@ -8,7 +8,7 @@
#
# Usage:
#
-# ./spec/support/generate-seed-repo-rb > spec/support/seed_repo.rb
+# ./spec/support/generate-seed-repo-rb > spec/support/helpers/seed_repo.rb
#
#
diff --git a/spec/support/gitlab-git-test.git/README.md b/spec/support/gitlab-git-test.git/README.md
index f072cd421be..f757e613ee6 100644
--- a/spec/support/gitlab-git-test.git/README.md
+++ b/spec/support/gitlab-git-test.git/README.md
@@ -12,5 +12,5 @@ inflate the size of the gitlab-ce repository.
- make changes in your local clone of gitlab-git-test
- run `git push` which will push to your local source `gitlab-ce/spec/support/gitlab-git-test.git`
- in gitlab-ce: run `spec/support/prepare-gitlab-git-test-for-commit`
-- in gitlab-ce: `git add spec/support/seed_repo.rb spec/support/gitlab-git-test.git`
+- in gitlab-ce: `git add spec/support/helpers/seed_repo.rb spec/support/gitlab-git-test.git`
- commit your changes in gitlab-ce
diff --git a/spec/support/api_helpers.rb b/spec/support/helpers/api_helpers.rb
index ac0c7a9b493..ac0c7a9b493 100644
--- a/spec/support/api_helpers.rb
+++ b/spec/support/helpers/api_helpers.rb
diff --git a/spec/support/bare_repo_operations.rb b/spec/support/helpers/bare_repo_operations.rb
index 3f4a4243cb6..3f4a4243cb6 100644
--- a/spec/support/bare_repo_operations.rb
+++ b/spec/support/helpers/bare_repo_operations.rb
diff --git a/spec/support/board_helpers.rb b/spec/support/helpers/board_helpers.rb
index 507d0432d7f..507d0432d7f 100644
--- a/spec/support/board_helpers.rb
+++ b/spec/support/helpers/board_helpers.rb
diff --git a/spec/support/capybara_helpers.rb b/spec/support/helpers/capybara_helpers.rb
index 868233416bf..bcc2df44708 100644
--- a/spec/support/capybara_helpers.rb
+++ b/spec/support/helpers/capybara_helpers.rb
@@ -41,7 +41,3 @@ module CapybaraHelpers
page.driver.browser.manage.delete_cookie('_gitlab_session')
end
end
-
-RSpec.configure do |config|
- config.include CapybaraHelpers, type: :feature
-end
diff --git a/spec/support/cookie_helper.rb b/spec/support/helpers/cookie_helper.rb
index 5ff7b0b68c9..5ff7b0b68c9 100644
--- a/spec/support/cookie_helper.rb
+++ b/spec/support/helpers/cookie_helper.rb
diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb
index 73cc64c0b74..55359d36597 100644
--- a/spec/support/cycle_analytics_helpers.rb
+++ b/spec/support/helpers/cycle_analytics_helpers.rb
@@ -135,7 +135,3 @@ module CycleAnalyticsHelpers
end
end
end
-
-RSpec.configure do |config|
- config.include CycleAnalyticsHelpers
-end
diff --git a/spec/support/database_connection_helpers.rb b/spec/support/helpers/database_connection_helpers.rb
index 763329499f0..763329499f0 100644
--- a/spec/support/database_connection_helpers.rb
+++ b/spec/support/helpers/database_connection_helpers.rb
diff --git a/spec/support/devise_helpers.rb b/spec/support/helpers/devise_helpers.rb
index 66874e10f38..66874e10f38 100644
--- a/spec/support/devise_helpers.rb
+++ b/spec/support/helpers/devise_helpers.rb
diff --git a/spec/support/drag_to_helper.rb b/spec/support/helpers/drag_to_helper.rb
index ae149631ed9..ae149631ed9 100644
--- a/spec/support/drag_to_helper.rb
+++ b/spec/support/helpers/drag_to_helper.rb
diff --git a/spec/support/dropzone_helper.rb b/spec/support/helpers/dropzone_helper.rb
index fe72d320fcf..fe72d320fcf 100644
--- a/spec/support/dropzone_helper.rb
+++ b/spec/support/helpers/dropzone_helper.rb
diff --git a/spec/support/email_helpers.rb b/spec/support/helpers/email_helpers.rb
index 1fb8252459f..1fb8252459f 100644
--- a/spec/support/email_helpers.rb
+++ b/spec/support/helpers/email_helpers.rb
diff --git a/spec/support/fake_migration_classes.rb b/spec/support/helpers/fake_migration_classes.rb
index b0fc8422857..b0fc8422857 100644
--- a/spec/support/fake_migration_classes.rb
+++ b/spec/support/helpers/fake_migration_classes.rb
diff --git a/spec/support/fake_u2f_device.rb b/spec/support/helpers/fake_u2f_device.rb
index a7605cd483a..a7605cd483a 100644
--- a/spec/support/fake_u2f_device.rb
+++ b/spec/support/helpers/fake_u2f_device.rb
diff --git a/spec/support/filter_item_select_helper.rb b/spec/support/helpers/filter_item_select_helper.rb
index 519e84d359e..519e84d359e 100644
--- a/spec/support/filter_item_select_helper.rb
+++ b/spec/support/helpers/filter_item_select_helper.rb
diff --git a/spec/support/filter_spec_helper.rb b/spec/support/helpers/filter_spec_helper.rb
index 721d359c2ee..721d359c2ee 100644
--- a/spec/support/filter_spec_helper.rb
+++ b/spec/support/helpers/filter_spec_helper.rb
diff --git a/spec/support/filtered_search_helpers.rb b/spec/support/helpers/filtered_search_helpers.rb
index 5f42ff77fb2..5f42ff77fb2 100644
--- a/spec/support/filtered_search_helpers.rb
+++ b/spec/support/helpers/filtered_search_helpers.rb
diff --git a/spec/support/fixture_helpers.rb b/spec/support/helpers/fixture_helpers.rb
index 8854382dc6b..611d19f36a0 100644
--- a/spec/support/fixture_helpers.rb
+++ b/spec/support/helpers/fixture_helpers.rb
@@ -9,7 +9,3 @@ module FixtureHelpers
File.expand_path(Rails.root.join(dir, 'spec', 'fixtures', filename))
end
end
-
-RSpec.configure do |config|
- config.include FixtureHelpers
-end
diff --git a/spec/support/git_http_helpers.rb b/spec/support/helpers/git_http_helpers.rb
index b8289e6c5f1..b8289e6c5f1 100644
--- a/spec/support/git_http_helpers.rb
+++ b/spec/support/helpers/git_http_helpers.rb
diff --git a/spec/support/helpers/gitlab_verify_helpers.rb b/spec/support/helpers/gitlab_verify_helpers.rb
new file mode 100644
index 00000000000..5df4bf24ec2
--- /dev/null
+++ b/spec/support/helpers/gitlab_verify_helpers.rb
@@ -0,0 +1,25 @@
+module GitlabVerifyHelpers
+ def collect_ranges(args = {})
+ verifier = described_class.new(args.merge(batch_size: 1))
+
+ collect_results(verifier).map { |range, _| range }
+ end
+
+ def collect_failures
+ verifier = described_class.new(batch_size: 1)
+
+ out = {}
+
+ collect_results(verifier).map { |_, failures| out.merge!(failures) }
+
+ out
+ end
+
+ def collect_results(verifier)
+ out = []
+
+ verifier.run_batches { |*args| out << args }
+
+ out
+ end
+end
diff --git a/spec/support/gpg_helpers.rb b/spec/support/helpers/gpg_helpers.rb
index 3f7279a50e0..3f7279a50e0 100644
--- a/spec/support/gpg_helpers.rb
+++ b/spec/support/helpers/gpg_helpers.rb
diff --git a/spec/support/import_spec_helper.rb b/spec/support/helpers/import_spec_helper.rb
index d4eced724fa..d4eced724fa 100644
--- a/spec/support/import_spec_helper.rb
+++ b/spec/support/helpers/import_spec_helper.rb
diff --git a/spec/support/input_helper.rb b/spec/support/helpers/input_helper.rb
index acbb42274ec..acbb42274ec 100644
--- a/spec/support/input_helper.rb
+++ b/spec/support/helpers/input_helper.rb
diff --git a/spec/support/inspect_requests.rb b/spec/support/helpers/inspect_requests.rb
index 88ddc5c7f6c..88ddc5c7f6c 100644
--- a/spec/support/inspect_requests.rb
+++ b/spec/support/helpers/inspect_requests.rb
diff --git a/spec/support/issue_helpers.rb b/spec/support/helpers/issue_helpers.rb
index ffd72515f37..ffd72515f37 100644
--- a/spec/support/issue_helpers.rb
+++ b/spec/support/helpers/issue_helpers.rb
diff --git a/spec/support/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb
index 2197bc9d853..2197bc9d853 100644
--- a/spec/support/javascript_fixtures_helpers.rb
+++ b/spec/support/helpers/javascript_fixtures_helpers.rb
diff --git a/spec/support/jira_service_helper.rb b/spec/support/helpers/jira_service_helper.rb
index 88a7aeba461..88a7aeba461 100644
--- a/spec/support/jira_service_helper.rb
+++ b/spec/support/helpers/jira_service_helper.rb
diff --git a/spec/support/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb
index e46b61b6461..e46b61b6461 100644
--- a/spec/support/kubernetes_helpers.rb
+++ b/spec/support/helpers/kubernetes_helpers.rb
diff --git a/spec/support/ldap_helpers.rb b/spec/support/helpers/ldap_helpers.rb
index 0e87b3d359d..0e87b3d359d 100644
--- a/spec/support/ldap_helpers.rb
+++ b/spec/support/helpers/ldap_helpers.rb
diff --git a/spec/support/live_debugger.rb b/spec/support/helpers/live_debugger.rb
index 911eb48a8ca..911eb48a8ca 100644
--- a/spec/support/live_debugger.rb
+++ b/spec/support/helpers/live_debugger.rb
diff --git a/spec/support/login_helpers.rb b/spec/support/helpers/login_helpers.rb
index db34090e971..db34090e971 100644
--- a/spec/support/login_helpers.rb
+++ b/spec/support/helpers/login_helpers.rb
diff --git a/spec/support/markdown_feature.rb b/spec/support/helpers/markdown_feature.rb
index 39e94ad53de..39e94ad53de 100644
--- a/spec/support/markdown_feature.rb
+++ b/spec/support/helpers/markdown_feature.rb
diff --git a/spec/support/merge_request_helpers.rb b/spec/support/helpers/merge_request_helpers.rb
index 772adff4626..772adff4626 100644
--- a/spec/support/merge_request_helpers.rb
+++ b/spec/support/helpers/merge_request_helpers.rb
diff --git a/spec/support/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb
index 5d6f662e8fe..5d6f662e8fe 100644
--- a/spec/support/migrations_helpers.rb
+++ b/spec/support/helpers/migrations_helpers.rb
diff --git a/spec/support/mobile_helpers.rb b/spec/support/helpers/mobile_helpers.rb
index 3b9eb84e824..3b9eb84e824 100644
--- a/spec/support/mobile_helpers.rb
+++ b/spec/support/helpers/mobile_helpers.rb
diff --git a/spec/support/project_forks_helper.rb b/spec/support/helpers/project_forks_helper.rb
index 2c501a2a27c..2c501a2a27c 100644
--- a/spec/support/project_forks_helper.rb
+++ b/spec/support/helpers/project_forks_helper.rb
diff --git a/spec/support/prometheus_helpers.rb b/spec/support/helpers/prometheus_helpers.rb
index 4212be2cc88..4212be2cc88 100644
--- a/spec/support/prometheus_helpers.rb
+++ b/spec/support/helpers/prometheus_helpers.rb
diff --git a/spec/support/helpers/query_recorder.rb b/spec/support/helpers/query_recorder.rb
new file mode 100644
index 00000000000..28536bbef5e
--- /dev/null
+++ b/spec/support/helpers/query_recorder.rb
@@ -0,0 +1,38 @@
+module ActiveRecord
+ class QueryRecorder
+ attr_reader :log, :cached
+
+ def initialize(&block)
+ @log = []
+ @cached = []
+ ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block)
+ end
+
+ def show_backtrace(values)
+ Rails.logger.debug("QueryRecorder SQL: #{values[:sql]}")
+ caller.each { |line| Rails.logger.debug(" --> #{line}") }
+ end
+
+ def callback(name, start, finish, message_id, values)
+ show_backtrace(values) if ENV['QUERY_RECORDER_DEBUG']
+
+ if values[:name]&.include?("CACHE")
+ @cached << values[:sql]
+ elsif !values[:name]&.include?("SCHEMA")
+ @log << values[:sql]
+ end
+ end
+
+ def count
+ @log.count
+ end
+
+ def cached_count
+ @cached.count
+ end
+
+ def log_message
+ @log.join("\n\n")
+ end
+ end
+end
diff --git a/spec/support/helpers/quick_actions_helpers.rb b/spec/support/helpers/quick_actions_helpers.rb
new file mode 100644
index 00000000000..361190aa352
--- /dev/null
+++ b/spec/support/helpers/quick_actions_helpers.rb
@@ -0,0 +1,10 @@
+module QuickActionsHelpers
+ def write_note(text)
+ Sidekiq::Testing.fake! do
+ page.within('.js-main-target-form') do
+ fill_in 'note[note]', with: text
+ find('.js-comment-submit-button').click
+ end
+ end
+ end
+end
diff --git a/spec/support/rake_helpers.rb b/spec/support/helpers/rake_helpers.rb
index 86bfeed107c..86bfeed107c 100644
--- a/spec/support/rake_helpers.rb
+++ b/spec/support/helpers/rake_helpers.rb
diff --git a/spec/support/reactive_caching_helpers.rb b/spec/support/helpers/reactive_caching_helpers.rb
index e22dd974c6a..e22dd974c6a 100644
--- a/spec/support/reactive_caching_helpers.rb
+++ b/spec/support/helpers/reactive_caching_helpers.rb
diff --git a/spec/support/redis_without_keys.rb b/spec/support/helpers/redis_without_keys.rb
index 6220167dee6..6220167dee6 100644
--- a/spec/support/redis_without_keys.rb
+++ b/spec/support/helpers/redis_without_keys.rb
diff --git a/spec/support/reference_parser_helpers.rb b/spec/support/helpers/reference_parser_helpers.rb
index c01897ed1a1..c01897ed1a1 100644
--- a/spec/support/reference_parser_helpers.rb
+++ b/spec/support/helpers/reference_parser_helpers.rb
diff --git a/spec/support/repo_helpers.rb b/spec/support/helpers/repo_helpers.rb
index 3c6956cf5e0..3c6956cf5e0 100644
--- a/spec/support/repo_helpers.rb
+++ b/spec/support/helpers/repo_helpers.rb
diff --git a/spec/support/search_helpers.rb b/spec/support/helpers/search_helpers.rb
index abbbb636d66..abbbb636d66 100644
--- a/spec/support/search_helpers.rb
+++ b/spec/support/helpers/search_helpers.rb
diff --git a/spec/support/seed_helper.rb b/spec/support/helpers/seed_helper.rb
index 11ef1fc477f..8fd107260cc 100644
--- a/spec/support/seed_helper.rb
+++ b/spec/support/helpers/seed_helper.rb
@@ -9,7 +9,7 @@ TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'.freeze
TEST_BROKEN_REPO_PATH = 'broken-repo.git'.freeze
module SeedHelper
- GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __FILE__).freeze
+ GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__).freeze
def ensure_seeds
if File.exist?(SEED_STORAGE_PATH)
@@ -108,11 +108,3 @@ bla/bla.txt
{ 'GIT_TEMPLATE_DIR' => '' }
end
end
-
-RSpec.configure do |config|
- config.include SeedHelper, :seed_helper
-
- config.before(:all, :seed_helper) do
- ensure_seeds
- end
-end
diff --git a/spec/support/seed_repo.rb b/spec/support/helpers/seed_repo.rb
index b4868e82cd7..b4868e82cd7 100644
--- a/spec/support/seed_repo.rb
+++ b/spec/support/helpers/seed_repo.rb
diff --git a/spec/support/select2_helper.rb b/spec/support/helpers/select2_helper.rb
index 90618ba5b19..90618ba5b19 100644
--- a/spec/support/select2_helper.rb
+++ b/spec/support/helpers/select2_helper.rb
diff --git a/spec/support/selection_helper.rb b/spec/support/helpers/selection_helper.rb
index b4725b137b2..b4725b137b2 100644
--- a/spec/support/selection_helper.rb
+++ b/spec/support/helpers/selection_helper.rb
diff --git a/spec/support/helpers/sorting_helper.rb b/spec/support/helpers/sorting_helper.rb
new file mode 100644
index 00000000000..577518d726c
--- /dev/null
+++ b/spec/support/helpers/sorting_helper.rb
@@ -0,0 +1,18 @@
+# Helper allows you to sort items
+#
+# Params
+# value - value for sorting
+#
+# Usage:
+# include SortingHelper
+#
+# sorting_by('Oldest updated')
+#
+module SortingHelper
+ def sorting_by(value)
+ find('button.dropdown-toggle').click
+ page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
+ click_link value
+ end
+ end
+end
diff --git a/spec/support/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb
index a75a3eaefcb..1823099dd9c 100644
--- a/spec/support/stub_configuration.rb
+++ b/spec/support/helpers/stub_configuration.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/hash/transform_values'
+require 'active_support/hash_with_indifferent_access'
+
module StubConfiguration
def stub_application_setting(messages)
add_predicates(messages)
diff --git a/spec/support/stub_env.rb b/spec/support/helpers/stub_env.rb
index 36b90fc68d6..36b90fc68d6 100644
--- a/spec/support/stub_env.rb
+++ b/spec/support/helpers/stub_env.rb
diff --git a/spec/support/stub_feature_flags.rb b/spec/support/helpers/stub_feature_flags.rb
index b96338bf548..b96338bf548 100644
--- a/spec/support/stub_feature_flags.rb
+++ b/spec/support/helpers/stub_feature_flags.rb
diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb
index c1618f5086c..c1618f5086c 100644
--- a/spec/support/stub_gitlab_calls.rb
+++ b/spec/support/helpers/stub_gitlab_calls.rb
diff --git a/spec/support/stub_gitlab_data.rb b/spec/support/helpers/stub_gitlab_data.rb
index fa402f35b95..fa402f35b95 100644
--- a/spec/support/stub_gitlab_data.rb
+++ b/spec/support/helpers/stub_gitlab_data.rb
diff --git a/spec/support/stub_object_storage.rb b/spec/support/helpers/stub_object_storage.rb
index 6e88641da42..19d744b959a 100644
--- a/spec/support/stub_object_storage.rb
+++ b/spec/support/helpers/stub_object_storage.rb
@@ -1,4 +1,4 @@
-module StubConfiguration
+module StubObjectStorage
def stub_object_storage_uploader(
config:,
uploader:,
diff --git a/spec/support/test_env.rb b/spec/support/helpers/test_env.rb
index d87f265cdf0..d87f265cdf0 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/helpers/test_env.rb
diff --git a/spec/support/upload_helpers.rb b/spec/support/helpers/upload_helpers.rb
index 5eead80c935..5eead80c935 100644
--- a/spec/support/upload_helpers.rb
+++ b/spec/support/helpers/upload_helpers.rb
diff --git a/spec/support/user_activities_helpers.rb b/spec/support/helpers/user_activities_helpers.rb
index 44feb104644..44feb104644 100644
--- a/spec/support/user_activities_helpers.rb
+++ b/spec/support/helpers/user_activities_helpers.rb
diff --git a/spec/support/wait_for_requests.rb b/spec/support/helpers/wait_for_requests.rb
index fda0e29f983..fda0e29f983 100644
--- a/spec/support/wait_for_requests.rb
+++ b/spec/support/helpers/wait_for_requests.rb
diff --git a/spec/support/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb
index ef1f9f68671..ef1f9f68671 100644
--- a/spec/support/workhorse_helpers.rb
+++ b/spec/support/helpers/workhorse_helpers.rb
diff --git a/spec/support/json_response_helpers.rb b/spec/support/json_response.rb
index aa235529c56..210b0e6d867 100644
--- a/spec/support/json_response_helpers.rb
+++ b/spec/support/json_response.rb
@@ -1,7 +1,3 @@
-shared_context 'JSON response' do
- let(:json_response) { JSON.parse(response.body) }
-end
-
RSpec.configure do |config|
config.include_context 'JSON response'
config.include_context 'JSON response', type: :request
diff --git a/spec/support/background_migrations_matchers.rb b/spec/support/matchers/background_migrations_matchers.rb
index f4127efc6ae..f4127efc6ae 100644
--- a/spec/support/background_migrations_matchers.rb
+++ b/spec/support/matchers/background_migrations_matchers.rb
diff --git a/spec/support/query_recorder.rb b/spec/support/matchers/exceed_query_limit.rb
index 8cf8f45a8b2..88d22a3ddd9 100644
--- a/spec/support/query_recorder.rb
+++ b/spec/support/matchers/exceed_query_limit.rb
@@ -1,42 +1,3 @@
-module ActiveRecord
- class QueryRecorder
- attr_reader :log, :cached
-
- def initialize(&block)
- @log = []
- @cached = []
- ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block)
- end
-
- def show_backtrace(values)
- Rails.logger.debug("QueryRecorder SQL: #{values[:sql]}")
- caller.each { |line| Rails.logger.debug(" --> #{line}") }
- end
-
- def callback(name, start, finish, message_id, values)
- show_backtrace(values) if ENV['QUERY_RECORDER_DEBUG']
-
- if values[:name]&.include?("CACHE")
- @cached << values[:sql]
- elsif !values[:name]&.include?("SCHEMA")
- @log << values[:sql]
- end
- end
-
- def count
- @log.count
- end
-
- def cached_count
- @cached.count
- end
-
- def log_message
- @log.join("\n\n")
- end
- end
-end
-
RSpec::Matchers.define :exceed_query_limit do |expected|
supports_block_expectations
diff --git a/spec/support/prepare-gitlab-git-test-for-commit b/spec/support/prepare-gitlab-git-test-for-commit
index 3047786a599..d08e3ba5481 100755
--- a/spec/support/prepare-gitlab-git-test-for-commit
+++ b/spec/support/prepare-gitlab-git-test-for-commit
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
abort unless [
- system('spec/support/generate-seed-repo-rb', out: 'spec/support/seed_repo.rb'),
+ system('spec/support/generate-seed-repo-rb', out: 'spec/support/helpers/seed_repo.rb'),
system('spec/support/unpack-gitlab-git-test')
].all?
diff --git a/spec/support/routing_helpers.rb b/spec/support/routing_helpers.rb
deleted file mode 100644
index af1f4760804..00000000000
--- a/spec/support/routing_helpers.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-RSpec.configure do |config|
- config.include GitlabRoutingHelper
-end
diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb
new file mode 100644
index 00000000000..dffab22d8b5
--- /dev/null
+++ b/spec/support/rspec.rb
@@ -0,0 +1,12 @@
+require_relative "helpers/stub_configuration"
+require_relative "helpers/stub_object_storage"
+require_relative "helpers/stub_env"
+
+RSpec.configure do |config|
+ config.mock_with :rspec
+ config.raise_errors_for_deprecations!
+
+ config.include StubConfiguration
+ config.include StubObjectStorage
+ config.include StubENV
+end
diff --git a/spec/support/seed.rb b/spec/support/seed.rb
new file mode 100644
index 00000000000..bea2e9c3044
--- /dev/null
+++ b/spec/support/seed.rb
@@ -0,0 +1,7 @@
+RSpec.configure do |config|
+ config.include SeedHelper, :seed_helper
+
+ config.before(:all, :seed_helper) do
+ ensure_seeds
+ end
+end
diff --git a/spec/support/shared_contexts/json_response_shared_context.rb b/spec/support/shared_contexts/json_response_shared_context.rb
new file mode 100644
index 00000000000..df5fc288089
--- /dev/null
+++ b/spec/support/shared_contexts/json_response_shared_context.rb
@@ -0,0 +1,3 @@
+shared_context 'JSON response' do
+ let(:json_response) { JSON.parse(response.body) }
+end
diff --git a/spec/support/services_shared_context.rb b/spec/support/shared_contexts/services_shared_context.rb
index 23f9b46ae0c..23f9b46ae0c 100644
--- a/spec/support/services_shared_context.rb
+++ b/spec/support/shared_contexts/services_shared_context.rb
diff --git a/spec/support/chat_slash_commands_shared_examples.rb b/spec/support/shared_examples/chat_slash_commands_shared_examples.rb
index dc97a39f051..dc97a39f051 100644
--- a/spec/support/chat_slash_commands_shared_examples.rb
+++ b/spec/support/shared_examples/chat_slash_commands_shared_examples.rb
diff --git a/spec/support/email_format_shared_examples.rb b/spec/support/shared_examples/email_format_shared_examples.rb
index b924a208e71..b924a208e71 100644
--- a/spec/support/email_format_shared_examples.rb
+++ b/spec/support/shared_examples/email_format_shared_examples.rb
diff --git a/spec/support/gitlab_verify.rb b/spec/support/shared_examples/gitlab_verify.rb
index 13e2e37624d..560913ca92f 100644
--- a/spec/support/gitlab_verify.rb
+++ b/spec/support/shared_examples/gitlab_verify.rb
@@ -17,29 +17,3 @@ RSpec.shared_examples 'Gitlab::Verify::BatchVerifier subclass' do
end
end
end
-
-module GitlabVerifyHelpers
- def collect_ranges(args = {})
- verifier = described_class.new(args.merge(batch_size: 1))
-
- collect_results(verifier).map { |range, _| range }
- end
-
- def collect_failures
- verifier = described_class.new(batch_size: 1)
-
- out = {}
-
- collect_results(verifier).map { |_, failures| out.merge!(failures) }
-
- out
- end
-
- def collect_results(verifier)
- out = []
-
- verifier.run_batches { |*args| out << args }
-
- out
- end
-end
diff --git a/spec/support/group_members_shared_example.rb b/spec/support/shared_examples/group_members_shared_example.rb
index 547c83c7955..547c83c7955 100644
--- a/spec/support/group_members_shared_example.rb
+++ b/spec/support/shared_examples/group_members_shared_example.rb
diff --git a/spec/support/issuable_shared_examples.rb b/spec/support/shared_examples/issuable_shared_examples.rb
index 42f3b4db23c..42f3b4db23c 100644
--- a/spec/support/issuable_shared_examples.rb
+++ b/spec/support/shared_examples/issuable_shared_examples.rb
diff --git a/spec/support/issuables_list_metadata_shared_examples.rb b/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb
index e61983c60b4..e61983c60b4 100644
--- a/spec/support/issuables_list_metadata_shared_examples.rb
+++ b/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb
diff --git a/spec/support/issue_tracker_service_shared_example.rb b/spec/support/shared_examples/issue_tracker_service_shared_example.rb
index a6ab03cb808..a6ab03cb808 100644
--- a/spec/support/issue_tracker_service_shared_example.rb
+++ b/spec/support/shared_examples/issue_tracker_service_shared_example.rb
diff --git a/spec/support/ldap_shared_examples.rb b/spec/support/shared_examples/ldap_shared_examples.rb
index 52c34e78965..52c34e78965 100644
--- a/spec/support/ldap_shared_examples.rb
+++ b/spec/support/shared_examples/ldap_shared_examples.rb
diff --git a/spec/support/legacy_path_redirect_shared_examples.rb b/spec/support/shared_examples/legacy_path_redirect_shared_examples.rb
index f300bdd48b1..f300bdd48b1 100644
--- a/spec/support/legacy_path_redirect_shared_examples.rb
+++ b/spec/support/shared_examples/legacy_path_redirect_shared_examples.rb
diff --git a/spec/support/malicious_regexp_shared_examples.rb b/spec/support/shared_examples/malicious_regexp_shared_examples.rb
index ac5d22298bb..ac5d22298bb 100644
--- a/spec/support/malicious_regexp_shared_examples.rb
+++ b/spec/support/shared_examples/malicious_regexp_shared_examples.rb
diff --git a/spec/support/mentionable_shared_examples.rb b/spec/support/shared_examples/mentionable_shared_examples.rb
index 1685decbe94..1685decbe94 100644
--- a/spec/support/mentionable_shared_examples.rb
+++ b/spec/support/shared_examples/mentionable_shared_examples.rb
diff --git a/spec/support/milestone_tabs_examples.rb b/spec/support/shared_examples/milestone_tabs_examples.rb
index 70b499198bf..70b499198bf 100644
--- a/spec/support/milestone_tabs_examples.rb
+++ b/spec/support/shared_examples/milestone_tabs_examples.rb
diff --git a/spec/support/notify_shared_examples.rb b/spec/support/shared_examples/notify_shared_examples.rb
index e2c23607406..e2c23607406 100644
--- a/spec/support/notify_shared_examples.rb
+++ b/spec/support/shared_examples/notify_shared_examples.rb
diff --git a/spec/support/reference_parser_shared_examples.rb b/spec/support/shared_examples/reference_parser_shared_examples.rb
index baf8bcc04b8..baf8bcc04b8 100644
--- a/spec/support/reference_parser_shared_examples.rb
+++ b/spec/support/shared_examples/reference_parser_shared_examples.rb
diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
index 07bc3a51fd8..07bc3a51fd8 100644
--- a/spec/support/slack_mattermost_notifications_shared_examples.rb
+++ b/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
diff --git a/spec/support/snippet_visibility.rb b/spec/support/shared_examples/snippet_visibility.rb
index 3a7c69b7877..3a7c69b7877 100644
--- a/spec/support/snippet_visibility.rb
+++ b/spec/support/shared_examples/snippet_visibility.rb
diff --git a/spec/support/snippets_shared_examples.rb b/spec/support/shared_examples/snippets_shared_examples.rb
index 85f0facd5c3..85f0facd5c3 100644
--- a/spec/support/snippets_shared_examples.rb
+++ b/spec/support/shared_examples/snippets_shared_examples.rb
diff --git a/spec/support/taskable_shared_examples.rb b/spec/support/shared_examples/taskable_shared_examples.rb
index 4056ff06b84..4056ff06b84 100644
--- a/spec/support/taskable_shared_examples.rb
+++ b/spec/support/shared_examples/taskable_shared_examples.rb
diff --git a/spec/support/time_tracking_shared_examples.rb b/spec/support/shared_examples/time_tracking_shared_examples.rb
index 909d4e2ee8d..909d4e2ee8d 100644
--- a/spec/support/time_tracking_shared_examples.rb
+++ b/spec/support/shared_examples/time_tracking_shared_examples.rb
diff --git a/spec/support/unique_ip_check_shared_examples.rb b/spec/support/shared_examples/unique_ip_check_shared_examples.rb
index e5c8ac6a004..e5c8ac6a004 100644
--- a/spec/support/unique_ip_check_shared_examples.rb
+++ b/spec/support/shared_examples/unique_ip_check_shared_examples.rb
diff --git a/spec/support/update_invalid_issuable.rb b/spec/support/shared_examples/update_invalid_issuable.rb
index 1490287681b..1490287681b 100644
--- a/spec/support/update_invalid_issuable.rb
+++ b/spec/support/shared_examples/update_invalid_issuable.rb
diff --git a/spec/support/updating_mentions_shared_examples.rb b/spec/support/shared_examples/updating_mentions_shared_examples.rb
index 5e3f19ba19e..5e3f19ba19e 100644
--- a/spec/support/updating_mentions_shared_examples.rb
+++ b/spec/support/shared_examples/updating_mentions_shared_examples.rb