diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/services/merge_requests | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/services/merge_requests')
6 files changed, 75 insertions, 25 deletions
diff --git a/spec/services/merge_requests/add_spent_time_service_spec.rb b/spec/services/merge_requests/add_spent_time_service_spec.rb index db3380e9582..1e0b3e07f26 100644 --- a/spec/services/merge_requests/add_spent_time_service_spec.rb +++ b/spec/services/merge_requests/add_spent_time_service_spec.rb @@ -8,7 +8,7 @@ RSpec.describe MergeRequests::AddSpentTimeService do let_it_be_with_reload(:merge_request) { create(:merge_request, :simple, :unique_branches, source_project: project) } let(:duration) { 1500 } - let(:params) { { spend_time: { duration: duration, user_id: user.id } } } + let(:params) { { spend_time: { duration: duration, summary: 'summary', user_id: user.id } } } let(:service) { described_class.new(project: project, current_user: user, params: params) } describe '#execute' do @@ -16,13 +16,14 @@ RSpec.describe MergeRequests::AddSpentTimeService do project.add_developer(user) end - it 'creates a new timelog with the specified duration' do + it 'creates a new timelog with the specified duration and summary' do expect { service.execute(merge_request) }.to change { Timelog.count }.from(0).to(1) timelog = merge_request.timelogs.last expect(timelog).not_to be_nil expect(timelog.time_spent).to eq(1500) + expect(timelog.summary).to eq('summary') end it 'creates a system note with the time added' do diff --git a/spec/services/merge_requests/close_service_spec.rb b/spec/services/merge_requests/close_service_spec.rb index f6336a85a25..86d972bc516 100644 --- a/spec/services/merge_requests/close_service_spec.rb +++ b/spec/services/merge_requests/close_service_spec.rb @@ -92,7 +92,7 @@ RSpec.describe MergeRequests::CloseService do end it 'clean up environments for the merge request' do - expect_next_instance_of(Ci::StopEnvironmentsService) do |service| + expect_next_instance_of(::Environments::StopService) do |service| expect(service).to receive(:execute_for_merge_request).with(merge_request) end diff --git a/spec/services/merge_requests/create_pipeline_service_spec.rb b/spec/services/merge_requests/create_pipeline_service_spec.rb index a0ac168f3d7..d84ce8d15b4 100644 --- a/spec/services/merge_requests/create_pipeline_service_spec.rb +++ b/spec/services/merge_requests/create_pipeline_service_spec.rb @@ -18,7 +18,7 @@ RSpec.describe MergeRequests::CreatePipelineService do end describe '#execute' do - subject { service.execute(merge_request) } + subject(:response) { service.execute(merge_request) } before do stub_ci_pipeline_yaml_file(YAML.dump(config)) @@ -39,14 +39,15 @@ RSpec.describe MergeRequests::CreatePipelineService do let(:source_project) { project } it 'creates a detached merge request pipeline' do - expect { subject }.to change { Ci::Pipeline.count }.by(1) + expect { response }.to change { Ci::Pipeline.count }.by(1) - expect(subject).to be_persisted - expect(subject).to be_detached_merge_request_pipeline + expect(response).to be_success + expect(response.payload).to be_persisted + expect(response.payload).to be_detached_merge_request_pipeline end it 'defaults to merge_request_event' do - expect(subject.source).to eq('merge_request_event') + expect(response.payload.source).to eq('merge_request_event') end context 'with fork merge request' do @@ -58,7 +59,7 @@ RSpec.describe MergeRequests::CreatePipelineService do let(:actor) { user } it 'creates a pipeline in the target project' do - expect(subject.project).to eq(project) + expect(response.payload.project).to eq(project) end context 'when source branch is protected' do @@ -66,7 +67,7 @@ RSpec.describe MergeRequests::CreatePipelineService do let!(:protected_branch) { create(:protected_branch, name: '*', project: project) } it 'creates a pipeline in the source project' do - expect(subject.project).to eq(source_project) + expect(response.payload.project).to eq(source_project) end end @@ -74,7 +75,7 @@ RSpec.describe MergeRequests::CreatePipelineService do let!(:protected_branch) { create(:protected_branch, :developers_can_merge, name: '*', project: project) } it 'creates a pipeline in the target project' do - expect(subject.project).to eq(project) + expect(response.payload.project).to eq(project) end end end @@ -85,7 +86,7 @@ RSpec.describe MergeRequests::CreatePipelineService do end it 'creates a pipeline in the source project' do - expect(subject.project).to eq(source_project) + expect(response.payload.project).to eq(source_project) end end end @@ -99,15 +100,16 @@ RSpec.describe MergeRequests::CreatePipelineService do end it 'creates a pipeline in the source project' do - expect(subject.project).to eq(source_project) + expect(response.payload.project).to eq(source_project) end end context 'when actor does not have permission to create pipelines' do let(:actor) { create(:user) } - it 'returns nothing' do - expect(subject.full_error_messages).to include('Insufficient permissions to create a new pipeline') + it 'responds with error' do + expect(response).to be_error + expect(response.message).to include('Insufficient permissions to create a new pipeline') end end end @@ -139,7 +141,7 @@ RSpec.describe MergeRequests::CreatePipelineService do end it 'does not create a pipeline' do - expect { subject }.not_to change { Ci::Pipeline.count } + expect { response }.not_to change { Ci::Pipeline.count } end end @@ -154,7 +156,7 @@ RSpec.describe MergeRequests::CreatePipelineService do end it 'does not create a pipeline' do - expect { subject }.not_to change { Ci::Pipeline.count } + expect { response }.not_to change { Ci::Pipeline.count } end end end @@ -170,11 +172,12 @@ RSpec.describe MergeRequests::CreatePipelineService do } end - it 'creates a detached merge request pipeline' do - expect { subject }.to change { Ci::Pipeline.count }.by(1) + it 'creates a detached merge request pipeline', :aggregate_failures do + expect { response }.to change { Ci::Pipeline.count }.by(1) - expect(subject).to be_persisted - expect(subject).to be_detached_merge_request_pipeline + expect(response).to be_success + expect(response.payload).to be_persisted + expect(response.payload).to be_detached_merge_request_pipeline end end @@ -188,10 +191,25 @@ RSpec.describe MergeRequests::CreatePipelineService do } end - it 'does not create a pipeline' do - expect { subject }.not_to change { Ci::Pipeline.count } + it 'does not create a pipeline', :aggregate_failures do + expect { response }.not_to change { Ci::Pipeline.count } + expect(response).to be_error end end end + + context 'when merge request has no commits' do + before do + allow(merge_request).to receive(:has_no_commits?).and_return(true) + end + + it 'does not create a pipeline', :aggregate_failures do + expect { response }.not_to change { Ci::Pipeline.count } + + expect(response).to be_error + expect(response.message).to eq('Cannot create a pipeline for this merge request.') + expect(response.payload).to be_nil + end + end end end diff --git a/spec/services/merge_requests/merge_to_ref_service_spec.rb b/spec/services/merge_requests/merge_to_ref_service_spec.rb index bb764ff5672..8fc12c6c2b1 100644 --- a/spec/services/merge_requests/merge_to_ref_service_spec.rb +++ b/spec/services/merge_requests/merge_to_ref_service_spec.rb @@ -36,6 +36,37 @@ RSpec.describe MergeRequests::MergeToRefService do expect(repository.ref_exists?(target_ref)).to be(true) expect(ref_head.id).to eq(result[:commit_id]) end + + context 'cache_merge_to_ref_calls flag enabled', :use_clean_rails_memory_store_caching do + before do + stub_feature_flags(cache_merge_to_ref_calls: true) + + # warm the cache + # + service.execute(merge_request) + end + + it 'caches the response', :request_store do + expect { 3.times { service.execute(merge_request) } } + .not_to change(Gitlab::GitalyClient, :get_request_count) + end + end + + context 'cache_merge_to_ref_calls flag disabled', :use_clean_rails_memory_store_caching do + before do + stub_feature_flags(cache_merge_to_ref_calls: false) + + # warm the cache + # + service.execute(merge_request) + end + + it 'does not cache the response', :request_store do + expect(Gitlab::GitalyClient).to receive(:call).at_least(3).times.and_call_original + + 3.times { service.execute(merge_request) } + end + end end shared_examples_for 'successfully evaluates pre-condition checks' do diff --git a/spec/services/merge_requests/post_merge_service_spec.rb b/spec/services/merge_requests/post_merge_service_spec.rb index 14804aa33d4..8d9a32c3e9e 100644 --- a/spec/services/merge_requests/post_merge_service_spec.rb +++ b/spec/services/merge_requests/post_merge_service_spec.rb @@ -75,7 +75,7 @@ RSpec.describe MergeRequests::PostMergeService do end it 'clean up environments for the merge request' do - expect_next_instance_of(Ci::StopEnvironmentsService) do |stop_environment_service| + expect_next_instance_of(::Environments::StopService) do |stop_environment_service| expect(stop_environment_service).to receive(:execute_for_merge_request).with(merge_request) end 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 5f76f6f5c44..f00a8928109 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -743,7 +743,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it 'records an error' do service.execute - expect(service.errors).to eq(['Branch my-branch does not exist']) + expect(service.errors).to eq(["Target branch #{project.full_path}:my-branch does not exist"]) end end |