diff options
| author | Clement Ho <clemmakesapps@gmail.com> | 2018-04-24 00:21:38 +0000 |
|---|---|---|
| committer | Clement Ho <clemmakesapps@gmail.com> | 2018-04-24 00:21:38 +0000 |
| commit | 0d77b9c9ff66835ad73858f7136653a4eb782822 (patch) | |
| tree | f2c8fc037a34059a8418bd8258f9b52eff2eea8d /spec | |
| parent | c7dd05e968dd515810d79688ecde08cb3ca725ec (diff) | |
| parent | 54b97f9ca55eded812b3fa1de424158c4c6f2614 (diff) | |
| download | gitlab-ce-0d77b9c9ff66835ad73858f7136653a4eb782822.tar.gz | |
Merge branch 'master' into 'bootstrap4'
# Conflicts:
# app/views/projects/jobs/index.html.haml
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/import/bitbucket_controller_spec.rb | 5 | ||||
| -rw-r--r-- | spec/controllers/import/gitlab_controller_spec.rb | 5 | ||||
| -rw-r--r-- | spec/controllers/projects/forks_controller_spec.rb | 6 | ||||
| -rw-r--r-- | spec/factories/commits.rb | 2 | ||||
| -rw-r--r-- | spec/factories/gpg_key_subkeys.rb | 2 | ||||
| -rw-r--r-- | spec/factories/gpg_keys.rb | 2 | ||||
| -rw-r--r-- | spec/factories/gpg_signature.rb | 2 | ||||
| -rw-r--r-- | spec/factories/groups.rb | 8 | ||||
| -rw-r--r-- | spec/factories/namespaces.rb | 18 | ||||
| -rw-r--r-- | spec/factories/notes.rb | 2 | ||||
| -rw-r--r-- | spec/factories/projects.rb | 2 | ||||
| -rw-r--r-- | spec/fast_spec_helper.rb | 15 | ||||
| -rw-r--r-- | spec/features/projects/jobs/user_browses_jobs_spec.rb | 2 | ||||
| -rw-r--r-- | spec/features/projects/new_project_spec.rb | 4 | ||||
| -rw-r--r-- | spec/lib/gitlab/bitbucket_import/project_creator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/lib/gitlab/gitlab_import/project_creator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/lib/gitlab/google_code_import/project_creator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/lib/gitlab/legacy_github_import/project_creator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/lib/gitlab_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/concerns/avatarable_spec.rb | 16 | ||||
| -rw-r--r-- | spec/models/project_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 8 | ||||
| -rw-r--r-- | spec/services/groups/nested_create_service_spec.rb | 7 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 59 | ||||
| -rw-r--r-- | spec/support/capybara.rb | 2 | ||||
| -rw-r--r-- | spec/support/controllers/githubish_import_controller_shared_examples.rb | 9 | ||||
| -rw-r--r-- | spec/support/factory_bot.rb | 3 | ||||
| -rwxr-xr-x | spec/support/generate-seed-repo-rb | 2 | ||||
| -rw-r--r-- | spec/support/gitlab-git-test.git/README.md | 2 | ||||
| -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.rb | 25 | ||||
| -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.rb | 38 | ||||
| -rw-r--r-- | spec/support/helpers/quick_actions_helpers.rb | 10 | ||||
| -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.rb | 18 | ||||
| -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-x | spec/support/prepare-gitlab-git-test-for-commit | 2 | ||||
| -rw-r--r-- | spec/support/routing_helpers.rb | 3 | ||||
| -rw-r--r-- | spec/support/rspec.rb | 12 | ||||
| -rw-r--r-- | spec/support/seed.rb | 7 | ||||
| -rw-r--r-- | spec/support/shared_contexts/json_response_shared_context.rb | 3 | ||||
| -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 |
120 files changed, 255 insertions, 162 deletions
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/jobs/user_browses_jobs_spec.rb b/spec/features/projects/jobs/user_browses_jobs_spec.rb index 36ebbeadd4a..786ec327b92 100644 --- a/spec/features/projects/jobs/user_browses_jobs_spec.rb +++ b/spec/features/projects/jobs/user_browses_jobs_spec.rb @@ -26,7 +26,7 @@ describe 'User browses jobs' do page.within('.nav-controls') do ci_lint_tool_link = page.find_link('CI lint') - expect(ci_lint_tool_link[:href]).to end_with(ci_lint_path) + expect(ci_lint_tool_link[:href]).to end_with(project_ci_lint_path(project)) end end 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 b85fde222ea..b85fde222ea 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 9dc1f1de436..9dc1f1de436 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 |
