diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-06 18:13:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-06 18:13:23 +0300 |
commit | b333706699e505b2a0a4fa9cc64b9d2358f271a5 (patch) | |
tree | 8d7f450089b32bcf038269c5e2849887b45c212d /spec | |
parent | 65b6ccd12e2e440baafd88851470d032c6ebe2c5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
14 files changed, 390 insertions, 145 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index ed5e32df8ea..9c4baeae836 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -896,12 +896,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :exposed_artifacts, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :exposed_artifacts, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end describe 'permissions on a public project with private CI/CD' do @@ -1031,12 +1032,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :coverage_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :coverage_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end describe 'permissions on a public project with private CI/CD' do @@ -1161,12 +1163,13 @@ RSpec.describe Projects::MergeRequestsController do end subject(:get_codequality_mr_diff_reports) do - get :codequality_mr_diff_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :codequality_mr_diff_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end context 'permissions on a public project with private CI/CD' do @@ -1264,12 +1267,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :terraform_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :terraform_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end describe 'permissions on a public project with private CI/CD' do @@ -1394,12 +1398,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :test_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :test_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end before do @@ -1522,12 +1527,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :accessibility_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :accessibility_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end context 'permissions on a public project with private CI/CD' do @@ -1642,12 +1648,13 @@ RSpec.describe Projects::MergeRequestsController do end subject do - get :codequality_reports, params: { - namespace_id: project.namespace.to_param, - project_id: project, - id: merge_request.iid - }, - format: :json + get :codequality_reports, + params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json end context 'permissions on a public project with private CI/CD' do diff --git a/spec/graphql/types/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb index f652ba2a470..f57e6ab3ce7 100644 --- a/spec/graphql/types/environment_type_spec.rb +++ b/spec/graphql/types/environment_type_spec.rb @@ -8,6 +8,7 @@ RSpec.describe GitlabSchema.types['Environment'] do it 'has the expected fields' do expected_fields = %w[ name id state metrics_dashboard latest_opened_most_severe_alert path external_url deployments + slug createdAt updatedAt autoStopAt autoDeleteAt tier environmentType ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb index 59fc278543f..a7d756a67a1 100644 --- a/spec/helpers/projects/pipeline_helper_spec.rb +++ b/spec/helpers/projects/pipeline_helper_spec.rb @@ -19,7 +19,6 @@ RSpec.describe Projects::PipelineHelper do it 'returns pipeline tabs data' do expect(pipeline_tabs_data).to include({ - can_generate_codequality_reports: pipeline.can_generate_codequality_reports?.to_json, failed_jobs_count: pipeline.failed_builds.count, failed_jobs_summary: prepare_failed_jobs_summary_data(pipeline.failed_builds), full_path: project.full_path, @@ -33,7 +32,8 @@ RSpec.describe Projects::PipelineHelper do blob_path: project_blob_path(project, pipeline.sha), has_test_report: pipeline.has_reports?(Ci::JobArtifact.of_report_type(:test)), empty_state_image_path: match_asset_path('illustrations/empty-state/empty-test-cases-lg.svg'), - artifacts_expired_image_path: match_asset_path('illustrations/pipeline.svg') + artifacts_expired_image_path: match_asset_path('illustrations/pipeline.svg'), + tests_count: pipeline.test_report_summary.total[:count] }) end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 04c066986b7..7365a3c3276 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1147,37 +1147,23 @@ RSpec.describe ProjectsHelper do context 'with the setting enabled' do before do stub_application_setting(delete_inactive_projects: true) + stub_application_setting(inactive_projects_min_size_mb: 0) + stub_application_setting(inactive_projects_send_warning_email_after_months: 1) end - context 'with the feature flag disabled' do - before do - stub_feature_flags(inactive_projects_deletion: false) - end - + context 'with an active project' do it_behaves_like 'does not show the banner' end - context 'with the feature flag enabled' do + context 'with an inactive project' do before do - stub_feature_flags(inactive_projects_deletion: true) - stub_application_setting(inactive_projects_min_size_mb: 0) - stub_application_setting(inactive_projects_send_warning_email_after_months: 1) + project.statistics.storage_size = 1.megabyte + project.last_activity_at = 1.year.ago + project.save! end - context 'with an active project' do - it_behaves_like 'does not show the banner' - end - - context 'with an inactive project' do - before do - project.statistics.storage_size = 1.megabyte - project.last_activity_at = 1.year.ago - project.save! - end - - it 'shows the banner' do - expect(helper.show_inactive_project_deletion_banner?(project)).to be(true) - end + it 'shows the banner' do + expect(helper.show_inactive_project_deletion_banner?(project)).to be(true) end end end diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 5d854f0c9d1..7e8aaa3cdf4 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -56,6 +56,85 @@ RSpec.describe Gitlab::GitalyClient::OperationService do Gitlab::Git::PreReceiveError, "something failed") end end + + context 'with structured errors' do + context 'with CustomHookError' do + let(:stdout) { nil } + let(:stderr) { nil } + let(:error_message) { "error_message" } + + let(:custom_hook_error) do + new_detailed_error( + GRPC::Core::StatusCodes::PERMISSION_DENIED, + error_message, + Gitaly::UserCreateBranchError.new( + custom_hook: Gitaly::CustomHookError.new( + stdout: stdout, + stderr: stderr, + hook_type: Gitaly::CustomHookError::HookType::HOOK_TYPE_PRERECEIVE + ))) + end + + shared_examples 'failed branch creation' do + it 'raised a PreRecieveError' do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_create_branch) + .and_raise(custom_hook_error) + + expect { subject }.to raise_error do |error| + expect(error).to be_a(Gitlab::Git::PreReceiveError) + expect(error.message).to eq(expected_message) + expect(error.raw_message).to eq(expected_raw_message) + end + end + end + + context 'when details contain stderr without prefix' do + let(:stderr) { "something" } + let(:stdout) { "GL-HOOK-ERR: stdout is overridden by stderr" } + let(:expected_message) { error_message } + let(:expected_raw_message) { stderr } + + it_behaves_like 'failed branch creation' + end + + context 'when details contain stderr with prefix' do + let(:stderr) { "GL-HOOK-ERR: something" } + let(:stdout) { "GL-HOOK-ERR: stdout is overridden by stderr" } + let(:expected_message) { "something" } + let(:expected_raw_message) { stderr } + + it_behaves_like 'failed branch creation' + end + + context 'when details contain stdout without prefix' do + let(:stderr) { " \n" } + let(:stdout) { "something" } + let(:expected_message) { error_message } + let(:expected_raw_message) { stdout } + + it_behaves_like 'failed branch creation' + end + + context 'when details contain stdout with prefix' do + let(:stderr) { " \n" } + let(:stdout) { "GL-HOOK-ERR: something" } + let(:expected_message) { "something" } + let(:expected_raw_message) { stdout } + + it_behaves_like 'failed branch creation' + end + + context 'when details contain no stderr or stdout' do + let(:stderr) { " \n" } + let(:stdout) { "\n \n" } + let(:expected_message) { error_message } + let(:expected_raw_message) { "\n \n" } + + it_behaves_like 'failed branch creation' + end + end + end end describe '#user_update_branch' do diff --git a/spec/models/preloaders/project_policy_preloader_spec.rb b/spec/models/preloaders/project_policy_preloader_spec.rb new file mode 100644 index 00000000000..79f232f5ce2 --- /dev/null +++ b/spec/models/preloaders/project_policy_preloader_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Preloaders::ProjectPolicyPreloader do + let_it_be(:user) { create(:user) } + let_it_be(:root_parent) { create(:group, :private, name: 'root-1', path: 'root-1') } + let_it_be(:guest_project) { create(:project, name: 'public guest', path: 'public-guest') } + let_it_be(:private_maintainer_project) do + create(:project, :private, name: 'b private maintainer', path: 'b-private-maintainer', namespace: root_parent) + end + + let_it_be(:private_developer_project) do + create(:project, :private, name: 'c public developer', path: 'c-public-developer') + end + + let_it_be(:public_maintainer_project) do + create(:project, :private, name: 'a public maintainer', path: 'a-public-maintainer') + end + + let(:base_projects) do + Project.where(id: [guest_project, private_maintainer_project, private_developer_project, public_maintainer_project]) + end + + before_all do + guest_project.add_guest(user) + private_maintainer_project.add_maintainer(user) + private_developer_project.add_developer(user) + public_maintainer_project.add_maintainer(user) + end + + it 'avoids N+1 queries when authorizing a list of projects', :request_store do + preload_projects_for_policy(user) + control = ActiveRecord::QueryRecorder.new { authorize_all_projects(user) } + + new_project1 = create(:project, :private).tap { |project| project.add_maintainer(user) } + new_project2 = create(:project, :private, namespace: root_parent) + + another_root = create(:group, :private, name: 'root-3', path: 'root-3') + new_project3 = create(:project, :private, namespace: another_root).tap { |project| project.add_maintainer(user) } + + pristine_projects = Project.where(id: base_projects + [new_project1, new_project2, new_project3]) + + preload_projects_for_policy(user, pristine_projects) + expect { authorize_all_projects(user, pristine_projects) }.not_to exceed_query_limit(control) + end + + def authorize_all_projects(current_user, project_list = base_projects) + project_list.each { |project| current_user.can?(:read_project, project) } + end + + def preload_projects_for_policy(current_user, project_list = base_projects) + described_class.new(project_list, current_user).execute + end +end diff --git a/spec/models/preloaders/project_root_ancestor_preloader_spec.rb b/spec/models/preloaders/project_root_ancestor_preloader_spec.rb new file mode 100644 index 00000000000..30036a6a033 --- /dev/null +++ b/spec/models/preloaders/project_root_ancestor_preloader_spec.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Preloaders::ProjectRootAncestorPreloader do + let_it_be(:root_parent1) { create(:group, :private, name: 'root-1', path: 'root-1') } + let_it_be(:root_parent2) { create(:group, :private, name: 'root-2', path: 'root-2') } + let_it_be(:guest_project) { create(:project, name: 'public guest', path: 'public-guest') } + let_it_be(:private_maintainer_project) do + create(:project, :private, name: 'b private maintainer', path: 'b-private-maintainer', namespace: root_parent1) + end + + let_it_be(:private_developer_project) do + create(:project, :private, name: 'c public developer', path: 'c-public-developer') + end + + let_it_be(:public_maintainer_project) do + create(:project, :private, name: 'a public maintainer', path: 'a-public-maintainer', namespace: root_parent2) + end + + let(:root_query_regex) { /\ASELECT.+FROM "namespaces" WHERE "namespaces"."id" = \d+/ } + let(:additional_preloads) { [] } + let(:projects) { [guest_project, private_maintainer_project, private_developer_project, public_maintainer_project] } + let(:pristine_projects) { Project.where(id: projects) } + + shared_examples 'executes N matching DB queries' do |expected_query_count, query_method = nil| + it 'executes the specified root_ancestor queries' do + expect do + pristine_projects.each do |project| + root_ancestor = project.root_ancestor + + root_ancestor.public_send(query_method) if query_method.present? + end + end.to make_queries_matching(root_query_regex, expected_query_count) + end + + it 'strong_memoizes the correct root_ancestor' do + pristine_projects.each do |project| + expected_parent_id = project.root_ancestor&.id + + expect(project.parent_id).to eq(expected_parent_id) + end + end + end + + context 'when use_traversal_ids FF is enabled' do + context 'when the preloader is used' do + before do + preload_ancestors + end + + context 'when no additional preloads are provided' do + it_behaves_like 'executes N matching DB queries', 0 + end + + context 'when additional preloads are provided' do + let(:additional_preloads) { [:route] } + let(:root_query_regex) { /\ASELECT.+FROM "routes" WHERE "routes"."source_id" = \d+/ } + + it_behaves_like 'executes N matching DB queries', 0, :full_path + end + end + + context 'when the preloader is not used' do + it_behaves_like 'executes N matching DB queries', 4 + end + end + + context 'when use_traversal_ids FF is disabled' do + before do + stub_feature_flags(use_traversal_ids: false) + end + + context 'when the preloader is used' do + before do + preload_ancestors + end + + context 'when no additional preloads are provided' do + it_behaves_like 'executes N matching DB queries', 4 + end + + context 'when additional preloads are provided' do + let(:additional_preloads) { [:route] } + let(:root_query_regex) { /\ASELECT.+FROM "routes" WHERE "routes"."source_id" = \d+/ } + + it_behaves_like 'executes N matching DB queries', 4, :full_path + end + end + + context 'when the preloader is not used' do + it_behaves_like 'executes N matching DB queries', 4 + end + end + + def preload_ancestors + described_class.new(pristine_projects, :namespace, additional_preloads).execute + end +end diff --git a/spec/requests/api/graphql/project/environments_spec.rb b/spec/requests/api/graphql/project/environments_spec.rb new file mode 100644 index 00000000000..5bc3ae2563b --- /dev/null +++ b/spec/requests/api/graphql/project/environments_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Project Environments query' do + include GraphqlHelpers + + let_it_be(:project) { create(:project, :private, :repository) } + let_it_be(:environment) { create(:environment, project: project) } + let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } } + + subject { post_graphql(query, current_user: user) } + + let(:user) { developer } + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + environment(name: "#{environment.name}") { + slug + createdAt + updatedAt + autoStopAt + autoDeleteAt + tier + environmentType + } + } + } + ) + end + + it 'returns the specified fields of the environment', :aggregate_failures do + environment.update!(auto_stop_at: 1.day.ago, auto_delete_at: 2.days.ago, environment_type: 'review') + + subject + + environment_data = graphql_data.dig('project', 'environment') + expect(environment_data['slug']).to eq(environment.slug) + expect(environment_data['createdAt']).to eq(environment.created_at.iso8601) + expect(environment_data['updatedAt']).to eq(environment.updated_at.iso8601) + expect(environment_data['autoStopAt']).to eq(environment.auto_stop_at.iso8601) + expect(environment_data['autoDeleteAt']).to eq(environment.auto_delete_at.iso8601) + expect(environment_data['tier']).to eq(environment.tier.upcase) + expect(environment_data['environmentType']).to eq(environment.environment_type) + end +end diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index f701dd9c488..9317a661188 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -480,7 +480,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/blame/master/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/blame', action: 'show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/#{newline_file}" }) @@ -499,7 +499,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/blob/blob/master/blob/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/blob', action: 'show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "blob/master/blob/#{newline_file}" }) @@ -520,7 +520,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/tree/master/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/tree', action: 'show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/#{newline_file}" }) @@ -540,7 +540,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/find_file/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/find_file', action: 'show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "#{newline_file}" }) @@ -551,7 +551,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/files/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/find_file', action: 'list', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "#{newline_file}" }) @@ -570,7 +570,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/edit/master/docs/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/blob', action: 'edit', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/docs/#{newline_file}" }) @@ -584,7 +584,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/edit/master/docs/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/blob', action: 'edit', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/docs/#{newline_file}" }) @@ -600,7 +600,7 @@ RSpec.describe 'project routing' do newline_file = "new\n\nline.txt" url_encoded_newline_file = ERB::Util.url_encode(newline_file) assert_routing({ path: "/gitlab/gitlabhq/-/raw/master/#{url_encoded_newline_file}", - method: :get }, + method: :get }, { controller: 'projects/raw', action: 'show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: "master/#{newline_file}" }) @@ -889,8 +889,8 @@ RSpec.describe 'project routing' do describe Projects::Snippets::BlobsController, "routing" do it "to #raw" do expect(get('/gitlab/gitlabhq/-/snippets/1/raw/master/lib/version.rb')) - .to route_to('projects/snippets/blobs#raw', namespace_id: 'gitlab', - project_id: 'gitlabhq', snippet_id: '1', ref: 'master', path: 'lib/version.rb') + .to route_to('projects/snippets/blobs#raw', + namespace_id: 'gitlab', project_id: 'gitlabhq', snippet_id: '1', ref: 'master', path: 'lib/version.rb') end end diff --git a/spec/serializers/ci/lint/job_entity_spec.rb b/spec/serializers/ci/lint/job_entity_spec.rb index 2ef86cfd004..e1477612ad5 100644 --- a/spec/serializers/ci/lint/job_entity_spec.rb +++ b/spec/serializers/ci/lint/job_entity_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ci::Lint::JobEntity, :aggregate_failures do stage: 'test', before_script: ['bundle install', 'bundle exec rake db:create'], script: ["rake spec"], - after_script: ["rake spec"], + after_script: ["rake spec"], tag_list: %w[ruby postgres], environment: { name: 'hello', url: 'world' }, when: 'on_success', diff --git a/spec/serializers/container_repository_entity_spec.rb b/spec/serializers/container_repository_entity_spec.rb index 9ea00bc79e1..00e6a26d0be 100644 --- a/spec/serializers/container_repository_entity_spec.rb +++ b/spec/serializers/container_repository_entity_spec.rb @@ -14,8 +14,7 @@ RSpec.describe ContainerRepositoryEntity do before do stub_container_registry_config(enabled: true) - stub_container_registry_tags(repository: :any, - tags: %w[stable latest]) + stub_container_registry_tags(repository: :any, tags: %w[stable latest]) allow(request).to receive(:project).and_return(project) allow(request).to receive(:current_user).and_return(user) end diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index a017f7523e9..433ce344680 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -61,8 +61,7 @@ RSpec.describe DeploymentEntity do context 'when the pipeline has another manual action' do let!(:other_build) do - create(:ci_build, :manual, name: 'another deploy', - pipeline: pipeline, environment: build.environment) + create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline, environment: build.environment) end let!(:other_deployment) { create(:deployment, deployable: build) } diff --git a/spec/serializers/merge_request_metrics_helper_spec.rb b/spec/serializers/merge_request_metrics_helper_spec.rb index 8f683df1faa..ec764bf7853 100644 --- a/spec/serializers/merge_request_metrics_helper_spec.rb +++ b/spec/serializers/merge_request_metrics_helper_spec.rb @@ -57,9 +57,9 @@ RSpec.describe MergeRequestMetricsHelper do expect(MergeRequest::Metrics).to receive(:new) .with(latest_closed_at: closed_event&.updated_at, - latest_closed_by: closed_event&.author, - merged_at: merge_event&.updated_at, - merged_by: merge_event&.author) + latest_closed_by: closed_event&.author, + merged_at: merge_event&.updated_at, + merged_by: merge_event&.author) .and_call_original subject diff --git a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb index ec10c66968d..50b5b0a6e7b 100644 --- a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb +++ b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb @@ -85,86 +85,58 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do end end - context 'when delete inactive projects feature is enabled' do + context 'when delete inactive projects feature is enabled', :clean_gitlab_redis_shared_state, :sidekiq_inline do before do stub_application_setting(delete_inactive_projects: true) end - context 'when feature flag is disabled' do - before do - stub_feature_flags(inactive_projects_deletion: false) - end - - it 'does not invoke Projects::InactiveProjectsDeletionNotificationWorker' do - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) - expect(::Projects::DestroyService).not_to receive(:new) - - worker.perform - end - - it 'does not delete the inactive projects' do - worker.perform - - expect(inactive_large_project.reload.pending_delete).to eq(false) + it 'invokes Projects::InactiveProjectsDeletionNotificationWorker for inactive projects' do + Gitlab::Redis::SharedState.with do |redis| + expect(redis).to receive(:hset).with('inactive_projects_deletion_warning_email_notified', + "project:#{inactive_large_project.id}", Date.current) end + expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_async).with( + inactive_large_project.id, deletion_date).and_call_original + expect(::Projects::DestroyService).not_to receive(:new) - it_behaves_like 'worker is running for more than 4 minutes' - it_behaves_like 'worker finishes processing in less than 4 minutes' + worker.perform end - context 'when feature flag is enabled', :clean_gitlab_redis_shared_state, :sidekiq_inline do - before do - stub_feature_flags(inactive_projects_deletion: true) - end - - it 'invokes Projects::InactiveProjectsDeletionNotificationWorker for inactive projects' do - Gitlab::Redis::SharedState.with do |redis| - expect(redis).to receive(:hset).with('inactive_projects_deletion_warning_email_notified', - "project:#{inactive_large_project.id}", Date.current) - end - expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_async).with( - inactive_large_project.id, deletion_date).and_call_original - expect(::Projects::DestroyService).not_to receive(:new) - - worker.perform + it 'does not invoke InactiveProjectsDeletionNotificationWorker for already notified inactive projects' do + Gitlab::Redis::SharedState.with do |redis| + redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}", + Date.current.to_s) end - it 'does not invoke InactiveProjectsDeletionNotificationWorker for already notified inactive projects' do - Gitlab::Redis::SharedState.with do |redis| - redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}", - Date.current.to_s) - end + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) + expect(::Projects::DestroyService).not_to receive(:new) - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) - expect(::Projects::DestroyService).not_to receive(:new) + worker.perform + end - worker.perform + it 'invokes Projects::DestroyService for projects that are inactive even after being notified' do + Gitlab::Redis::SharedState.with do |redis| + redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}", + 15.months.ago.to_date.to_s) end - it 'invokes Projects::DestroyService for projects that are inactive even after being notified' do - Gitlab::Redis::SharedState.with do |redis| - redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}", - 15.months.ago.to_date.to_s) - end - - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) - expect(::Projects::DestroyService).to receive(:new).with(inactive_large_project, admin_user, {}) - .at_least(:once).and_call_original + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) + expect(::Projects::DestroyService).to receive(:new).with(inactive_large_project, admin_user, {}) + .at_least(:once).and_call_original - worker.perform + worker.perform - expect(inactive_large_project.reload.pending_delete).to eq(true) + expect(inactive_large_project.reload.pending_delete).to eq(true) - Gitlab::Redis::SharedState.with do |redis| - expect(redis.hget('inactive_projects_deletion_warning_email_notified', - "project:#{inactive_large_project.id}")).to be_nil - end + Gitlab::Redis::SharedState.with do |redis| + expect(redis.hget('inactive_projects_deletion_warning_email_notified', + "project:#{inactive_large_project.id}")).to be_nil end - - it_behaves_like 'worker is running for more than 4 minutes' - it_behaves_like 'worker finishes processing in less than 4 minutes' end + it_behaves_like 'worker is running for more than 4 minutes' + it_behaves_like 'worker finishes processing in less than 4 minutes' + it_behaves_like 'an idempotent worker' end end |