diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 09:11:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 09:11:17 +0000 |
commit | 67cdffe4deb5c887c17115d4f974c0e8a267ffd2 (patch) | |
tree | 05023f6d748b4ca308eb9d61d28696726cad85f3 /spec | |
parent | 93c27b216aa57d57ebd8f5f2581e45dc300324b8 (diff) | |
download | gitlab-ce-67cdffe4deb5c887c17115d4f974c0e8a267ffd2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 199 insertions, 167 deletions
diff --git a/spec/features/import/manifest_import_spec.rb b/spec/features/import/manifest_import_spec.rb index dfd6211a683..ce22171a560 100644 --- a/spec/features/import/manifest_import_spec.rb +++ b/spec/features/import/manifest_import_spec.rb @@ -37,7 +37,7 @@ RSpec.describe 'Import multiple repositories by uploading a manifest file', :js wait_for_requests page.within(second_row) do - expect(page).to have_content 'Done' + expect(page).to have_content 'Complete' expect(page).to have_content("#{group.full_path}/build/blueprint") end end diff --git a/spec/fixtures/ce_sample_schema.json b/spec/fixtures/ce_sample_schema.json new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/spec/fixtures/ce_sample_schema.json diff --git a/spec/services/ci/create_job_artifacts_service_spec.rb b/spec/services/ci/job_artifacts/create_service_spec.rb index 1efd1d390a2..22aa9e62c6f 100644 --- a/spec/services/ci/create_job_artifacts_service_spec.rb +++ b/spec/services/ci/job_artifacts/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::CreateJobArtifactsService do +RSpec.describe Ci::JobArtifacts::CreateService do let_it_be(:project) { create(:project) } let(:service) { described_class.new(job) } let(:job) { create(:ci_build, project: project) } diff --git a/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb b/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb index d315dd35632..04fa55068f2 100644 --- a/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb +++ b/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared_state do +RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_shared_state do include ExclusiveLeaseHelpers let(:service) { described_class.new } @@ -24,7 +24,7 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared job = create(:ci_build, pipeline: artifact.job.pipeline) create(:ci_job_artifact, :archive, :expired, job: job) - stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_LIMIT', 1) + stub_const("#{described_class}::LOOP_LIMIT", 1) end it 'performs the smallest number of queries for job_artifacts' do @@ -113,7 +113,7 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared context 'when failed to destroy artifact' do before do - stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_LIMIT', 10) + stub_const("#{described_class}::LOOP_LIMIT", 10) end context 'when the import fails' do @@ -159,8 +159,8 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared let!(:second_artifact) { create(:ci_job_artifact, expire_at: 1.day.ago) } before do - stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_TIMEOUT', 0.seconds) - stub_const('Ci::DestroyExpiredJobArtifactsService::BATCH_SIZE', 1) + stub_const("#{described_class}::LOOP_TIMEOUT", 0.seconds) + stub_const("#{described_class}::BATCH_SIZE", 1) second_artifact.job.pipeline.unlocked! end @@ -176,8 +176,8 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared context 'when loop reached loop limit' do before do - stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_LIMIT', 1) - stub_const('Ci::DestroyExpiredJobArtifactsService::BATCH_SIZE', 1) + stub_const("#{described_class}::LOOP_LIMIT", 1) + stub_const("#{described_class}::BATCH_SIZE", 1) second_artifact.job.pipeline.unlocked! end @@ -209,7 +209,7 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared context 'when there are artifacts more than batch sizes' do before do - stub_const('Ci::DestroyExpiredJobArtifactsService::BATCH_SIZE', 1) + stub_const("#{described_class}::BATCH_SIZE", 1) second_artifact.job.pipeline.unlocked! end diff --git a/spec/services/ci/job_artifacts_destroy_batch_service_spec.rb b/spec/services/ci/job_artifacts/destroy_batch_service_spec.rb index 74fbbf28ef1..52aaf73d67e 100644 --- a/spec/services/ci/job_artifacts_destroy_batch_service_spec.rb +++ b/spec/services/ci/job_artifacts/destroy_batch_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::JobArtifactsDestroyBatchService do +RSpec.describe Ci::JobArtifacts::DestroyBatchService do include ExclusiveLeaseHelpers let(:artifacts) { Ci::JobArtifact.all } diff --git a/spec/services/ci/pipeline_artifacts/destroy_expired_artifacts_service_spec.rb b/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb index ac1a590face..3dc4f35df22 100644 --- a/spec/services/ci/pipeline_artifacts/destroy_expired_artifacts_service_spec.rb +++ b/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineArtifacts::DestroyExpiredArtifactsService do +RSpec.describe Ci::PipelineArtifacts::DestroyAllExpiredService do let(:service) { described_class.new } describe '.execute' do @@ -10,7 +10,7 @@ RSpec.describe Ci::PipelineArtifacts::DestroyExpiredArtifactsService do context 'when timeout happens' do before do - stub_const('Ci::PipelineArtifacts::DestroyExpiredArtifactsService::LOOP_TIMEOUT', 0.1.seconds) + stub_const('Ci::PipelineArtifacts::DestroyAllExpiredService::LOOP_TIMEOUT', 0.1.seconds) allow(service).to receive(:destroy_artifacts_batch) { true } end @@ -27,8 +27,8 @@ RSpec.describe Ci::PipelineArtifacts::DestroyExpiredArtifactsService do context 'when the loop limit is reached' do before do - stub_const('::Ci::PipelineArtifacts::DestroyExpiredArtifactsService::LOOP_LIMIT', 1) - stub_const('::Ci::PipelineArtifacts::DestroyExpiredArtifactsService::BATCH_SIZE', 1) + stub_const('::Ci::PipelineArtifacts::DestroyAllExpiredService::LOOP_LIMIT', 1) + stub_const('::Ci::PipelineArtifacts::DestroyAllExpiredService::BATCH_SIZE', 1) create_list(:ci_pipeline_artifact, 2, expire_at: 1.week.ago) end @@ -44,7 +44,7 @@ RSpec.describe Ci::PipelineArtifacts::DestroyExpiredArtifactsService do context 'when there are artifacts more than batch sizes' do before do - stub_const('Ci::PipelineArtifacts::DestroyExpiredArtifactsService::BATCH_SIZE', 1) + stub_const('Ci::PipelineArtifacts::DestroyAllExpiredService::BATCH_SIZE', 1) create_list(:ci_pipeline_artifact, 2, expire_at: 1.week.ago) end diff --git a/spec/services/issuable/process_assignees_spec.rb b/spec/services/issuable/process_assignees_spec.rb index 876c84957cc..45d57a1772a 100644 --- a/spec/services/issuable/process_assignees_spec.rb +++ b/spec/services/issuable/process_assignees_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' RSpec.describe Issuable::ProcessAssignees do describe '#execute' do - it 'returns assignee_ids when assignee_ids are specified' do + it 'returns assignee_ids when add_assignee_ids and remove_assignee_ids are not specified' do process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9), - add_assignee_ids: %w(2 4 6), - remove_assignee_ids: %w(4 7 11), + add_assignee_ids: nil, + remove_assignee_ids: nil, existing_assignee_ids: %w(1 3 9), extra_assignee_ids: %w(2 5 12)) result = process.execute @@ -15,19 +15,19 @@ RSpec.describe Issuable::ProcessAssignees do expect(result.sort).to eq(%w(5 7 9).sort) end - it 'combines other ids when assignee_ids is empty' do - process = Issuable::ProcessAssignees.new(assignee_ids: [], - add_assignee_ids: %w(2 4 6), - remove_assignee_ids: %w(4 7 11), + it 'combines other ids when assignee_ids is nil' do + process = Issuable::ProcessAssignees.new(assignee_ids: nil, + add_assignee_ids: nil, + remove_assignee_ids: nil, existing_assignee_ids: %w(1 3 11), extra_assignee_ids: %w(2 5 12)) result = process.execute - expect(result.sort).to eq(%w(1 2 3 5 6 12).sort) + expect(result.sort).to eq(%w(1 2 3 5 11 12).sort) end - it 'combines other ids when assignee_ids is nil' do - process = Issuable::ProcessAssignees.new(assignee_ids: nil, + it 'combines other ids when both add_assignee_ids and remove_assignee_ids are not empty' do + process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9), add_assignee_ids: %w(2 4 6), remove_assignee_ids: %w(4 7 11), existing_assignee_ids: %w(1 3 11), @@ -37,8 +37,8 @@ RSpec.describe Issuable::ProcessAssignees do expect(result.sort).to eq(%w(1 2 3 5 6 12).sort) end - it 'combines other ids when assignee_ids and add_assignee_ids are nil' do - process = Issuable::ProcessAssignees.new(assignee_ids: nil, + it 'combines other ids when remove_assignee_ids is not empty' do + process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9), add_assignee_ids: nil, remove_assignee_ids: %w(4 7 11), existing_assignee_ids: %w(1 3 11), @@ -48,8 +48,8 @@ RSpec.describe Issuable::ProcessAssignees do expect(result.sort).to eq(%w(1 2 3 5 12).sort) end - it 'combines other ids when assignee_ids and remove_assignee_ids are nil' do - process = Issuable::ProcessAssignees.new(assignee_ids: nil, + it 'combines other ids when add_assignee_ids is not empty' do + process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9), add_assignee_ids: %w(2 4 6), remove_assignee_ids: nil, existing_assignee_ids: %w(1 3 11), @@ -59,8 +59,8 @@ RSpec.describe Issuable::ProcessAssignees do expect(result.sort).to eq(%w(1 2 4 3 5 6 11 12).sort) end - it 'combines ids when only add_assignee_ids and remove_assignee_ids are passed' do - process = Issuable::ProcessAssignees.new(assignee_ids: nil, + it 'combines ids when existing_assignee_ids and extra_assignee_ids are omitted' do + process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9), add_assignee_ids: %w(2 4 6), remove_assignee_ids: %w(4 7 11)) result = process.execute diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb index c2769d4fa88..b5086ea3a82 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -6,10 +6,12 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do include ProjectForksHelper let_it_be(:project) { create(:project, :public, :repository) } - let_it_be(:user) { create(:user, developer_projects: [project]) } - let_it_be(:forked_project) { fork_project(project, user, repository: true) } + let_it_be(:user1) { create(:user, developer_projects: [project]) } + let_it_be(:user2) { create(:user, developer_projects: [project]) } + let_it_be(:user3) { create(:user, developer_projects: [project]) } + let_it_be(:forked_project) { fork_project(project, user1, repository: true) } - let(:service) { described_class.new(project, user, changes, push_options) } + let(:service) { described_class.new(project, user1, changes, push_options) } let(:source_branch) { 'fix' } let(:target_branch) { 'feature' } let(:title) { 'my title' } @@ -23,32 +25,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{project.default_branch}" } let(:error_mr_required) { "A merge_request.create push option is required to create a merge request for branch #{source_branch}" } - shared_examples_for 'a service that can create a merge request' do - subject(:last_mr) { MergeRequest.last } - - it 'creates a merge request with the correct target branch and assigned user' do - branch = push_options[:target] || project.default_branch - - expect { service.execute }.to change { MergeRequest.count }.by(1) - expect(last_mr.target_branch).to eq(branch) - expect(last_mr.assignees).to contain_exactly(user) - end - - context 'when project has been forked', :sidekiq_might_not_need_inline do - let(:forked_project) { fork_project(project, user, repository: true) } - let(:service) { described_class.new(forked_project, user, changes, push_options) } - - before do - allow(forked_project).to receive(:empty_repo?).and_return(false) - end - - it 'sets the correct source and target project' do - service.execute - - expect(last_mr.source_project).to eq(forked_project) - expect(last_mr.target_project).to eq(project) - end - end + before do + stub_licensed_features(multiple_merge_request_assignees: false) end shared_examples_for 'a service that can set the target of a merge request' do @@ -91,7 +69,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do expect(last_mr.auto_merge_enabled).to eq(true) expect(last_mr.auto_merge_strategy).to eq(AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS) - expect(last_mr.merge_user).to eq(user) + expect(last_mr.merge_user).to eq(user1) expect(last_mr.merge_params['sha']).to eq(change[:newrev]) end end @@ -116,12 +94,6 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do end end - shared_examples_for 'a service that does not create a merge request' do - it do - expect { service.execute }.not_to change { MergeRequest.count } - end - end - shared_examples_for 'a service that does not update a merge request' do it do expect { service.execute }.not_to change { MergeRequest.maximum(:updated_at) } @@ -133,6 +105,18 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do include_examples 'a service that does not update a merge request' end + shared_examples 'with a deleted branch' do + let(:changes) { deleted_branch_changes } + + it_behaves_like 'a service that does nothing' + end + + shared_examples 'with the project default branch' do + let(:changes) { default_branch_changes } + + it_behaves_like 'a service that does nothing' + end + describe '`create` push option' do let(:push_options) { { create: true } } @@ -155,17 +139,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that does not create a merge request' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`merge_when_pipeline_succeeds` push option' do @@ -217,17 +192,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can set the merge request to merge when pipeline succeeds' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`remove_source_branch` push option' do @@ -239,11 +205,9 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that does not create a merge request' it 'adds an error to the service' do - error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}" - service.execute - expect(service.errors).to include(error) + expect(service.errors).to include(error_mr_required) end context 'when coupled with the `create` push option' do @@ -281,17 +245,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can remove the source branch when it is merged' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`target` push option' do @@ -343,17 +298,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can set the target of a merge request' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`title` push option' do @@ -405,17 +351,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can set the title of a merge request' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`description` push option' do @@ -467,17 +404,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can set the description of a merge request' end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`label` push option' do @@ -529,17 +457,8 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can change labels of a merge request', 2 end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } - - it_behaves_like 'a service that does nothing' - end - - context 'with the project default branch' do - let(:changes) { default_branch_changes } - - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe '`unlabel` push option' do @@ -551,11 +470,9 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that does not create a merge request' it 'adds an error to the service' do - error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}" - service.execute - expect(service.errors).to include(error) + expect(service.errors).to include(error_mr_required) end context 'when coupled with the `create` push option' do @@ -572,11 +489,9 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that does not create a merge request' it 'adds an error to the service' do - error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}" - service.execute - expect(service.errors).to include(error) + expect(service.errors).to include(error_mr_required) end context 'when coupled with the `create` push option' do @@ -595,17 +510,42 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that can change labels of a merge request', 1 end - context 'with a deleted branch' do - let(:changes) { deleted_branch_changes } + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' + end + + shared_examples 'with an existing branch that has a merge request open in foss' do + let(:changes) { existing_branch_changes } + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)} - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'a service that does not create a merge request' + it_behaves_like 'a service that can change assignees of a merge request', 1 + end - context 'with the project default branch' do - let(:changes) { default_branch_changes } + describe '`assign` push option' do + let(:assigned) { { user2.id => 1, user3.id => 1 } } + let(:unassigned) { nil } + let(:push_options) { { assign: assigned, unassign: unassigned } } - it_behaves_like 'a service that does nothing' - end + it_behaves_like 'with a new branch', 1 + it_behaves_like 'with an existing branch but no open MR', 1 + it_behaves_like 'with an existing branch that has a merge request open in foss' + + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' + end + + describe '`unassign` push option' do + let(:assigned) { { user2.id => 1, user3.id => 1 } } + let(:unassigned) { { user1.id => 1, user3.id => 1 } } + let(:push_options) { { assign: assigned, unassign: unassigned } } + + it_behaves_like 'with a new branch', 1 + it_behaves_like 'with an existing branch but no open MR', 1 + it_behaves_like 'with an existing branch that has a merge request open in foss' + + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' end describe 'multiple pushed branches' do @@ -645,7 +585,9 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do end describe 'no user' do - let(:user) { nil } + let(:user1) { nil } + let(:user2) { nil } + let(:user3) { nil } let(:push_options) { { create: true } } let(:changes) { new_branch_changes } @@ -661,7 +603,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do let(:changes) { new_branch_changes } it 'records an error' do - Members::DestroyService.new(user).execute(ProjectMember.find_by!(user_id: user.id)) + Members::DestroyService.new(user1).execute(ProjectMember.find_by!(user_id: user1.id)) service.execute @@ -707,7 +649,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do end describe 'when MRs are not enabled' do - let(:project) { create(:project, :public, :repository).tap { |pr| pr.add_developer(user) } } + let(:project) { create(:project, :public, :repository).tap { |pr| pr.add_developer(user1) } } let(:push_options) { { create: true } } let(:changes) { new_branch_changes } diff --git a/spec/support/shared_examples/services/merge_request_shared_examples.rb b/spec/support/shared_examples/services/merge_request_shared_examples.rb index 56179b6cd00..178b6bc47e1 100644 --- a/spec/support/shared_examples/services/merge_request_shared_examples.rb +++ b/spec/support/shared_examples/services/merge_request_shared_examples.rb @@ -73,3 +73,93 @@ RSpec.shared_examples 'merge request reviewers cache counters invalidator' do described_class.new(project, user, {}).execute(merge_request) end end + +RSpec.shared_examples_for 'a service that can create a merge request' do + subject(:last_mr) { MergeRequest.last } + + it 'creates a merge request with the correct target branch' do + branch = push_options[:target] || project.default_branch + + expect { service.execute }.to change { MergeRequest.count }.by(1) + expect(last_mr.target_branch).to eq(branch) + end + + context 'when project has been forked', :sidekiq_might_not_need_inline do + let(:forked_project) { fork_project(project, user1, repository: true) } + let(:service) { described_class.new(forked_project, user1, changes, push_options) } + + before do + allow(forked_project).to receive(:empty_repo?).and_return(false) + end + + it 'sets the correct source and target project' do + service.execute + + expect(last_mr.source_project).to eq(forked_project) + expect(last_mr.target_project).to eq(project) + end + end +end + +RSpec.shared_examples_for 'a service that does not create a merge request' do + it do + expect { service.execute }.not_to change { MergeRequest.count } + end +end + +# In the non-foss version of GitLab, there can be many assignees, so +# there 'count' can be something other than 0 or 1. In the foss +# version of GitLab, there can be only one assignee though, so 'count' +# can only be 0 or 1. +RSpec.shared_examples_for 'a service that can change assignees of a merge request' do |count| + subject(:last_mr) { MergeRequest.last } + + it 'changes assignee count' do + service.execute + + expect(last_mr.assignees.count).to eq(count) + end +end + +RSpec.shared_examples 'with an existing branch that has a merge request open' do |count| + let(:changes) { existing_branch_changes } + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)} + + it_behaves_like 'a service that does not create a merge request' + it_behaves_like 'a service that can change assignees of a merge request', count +end + +RSpec.shared_examples 'when coupled with the `create` push option' do |count| + let(:push_options) { { create: true, assign: assigned, unassign: unassigned } } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can change assignees of a merge request', count +end + +RSpec.shared_examples 'with a new branch' do |count| + let(:changes) { new_branch_changes } + + it_behaves_like 'a service that does not create a merge request' + + it 'adds an error to the service' do + service.execute + + expect(service.errors).to include(error_mr_required) + end + + it_behaves_like 'when coupled with the `create` push option', count +end + +RSpec.shared_examples 'with an existing branch but no open MR' do |count| + let(:changes) { existing_branch_changes } + + it_behaves_like 'a service that does not create a merge request' + + it 'adds an error to the service' do + service.execute + + expect(service.errors).to include(error_mr_required) + end + + it_behaves_like 'when coupled with the `create` push option', count +end diff --git a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb index 2bdd8345374..ad9c08d02cb 100644 --- a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb +++ b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do end it 'executes a service' do - expect_next_instance_of(::Ci::PipelineArtifacts::DestroyExpiredArtifactsService) do |instance| + expect_next_instance_of(::Ci::PipelineArtifacts::DestroyAllExpiredService) do |instance| expect(instance).to receive(:execute) end diff --git a/spec/workers/expire_build_artifacts_worker_spec.rb b/spec/workers/expire_build_artifacts_worker_spec.rb index 6d73d715d21..3f8da3fb71c 100644 --- a/spec/workers/expire_build_artifacts_worker_spec.rb +++ b/spec/workers/expire_build_artifacts_worker_spec.rb @@ -7,7 +7,7 @@ RSpec.describe ExpireBuildArtifactsWorker do describe '#perform' do it 'executes a service' do - expect_next_instance_of(Ci::DestroyExpiredJobArtifactsService) do |instance| + expect_next_instance_of(Ci::JobArtifacts::DestroyAllExpiredService) do |instance| expect(instance).to receive(:execute).and_call_original end |