diff options
Diffstat (limited to 'spec/services/merge_requests')
6 files changed, 77 insertions, 40 deletions
diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index dc34546a599..9155db16d17 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -224,19 +224,6 @@ describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do end end - context 'when ci_use_merge_request_ref feature flag is false' do - before do - stub_feature_flags(ci_use_merge_request_ref: false) - end - - it 'create legacy detached merge request pipeline for non-fork merge request' do - merge_request.reload - - expect(merge_request.actual_head_pipeline) - .to be_legacy_detached_merge_request_pipeline - end - end - context 'when there are no commits between source branch and target branch' do let(:opts) do { diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index fa7f745d8a0..bcad822b1dc 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -118,7 +118,7 @@ describe MergeRequests::MergeService do it 'closes GitLab issue tracker issues' do issue = create :issue, project: project - commit = instance_double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.now, authored_date: Time.now) + commit = instance_double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.current, authored_date: Time.current) allow(merge_request).to receive(:commits).and_return([commit]) merge_request.cache_merge_request_closes_issues! diff --git a/spec/services/merge_requests/rebase_service_spec.rb b/spec/services/merge_requests/rebase_service_spec.rb index 22df3b84243..69d555f838d 100644 --- a/spec/services/merge_requests/rebase_service_spec.rb +++ b/spec/services/merge_requests/rebase_service_spec.rb @@ -72,12 +72,15 @@ describe MergeRequests::RebaseService do it_behaves_like 'sequence of failure and success' context 'when unexpected error occurs' do + let(:exception) { RuntimeError.new('Something went wrong') } + let(:merge_request_ref) { merge_request.to_reference(full: true) } + before do - allow(repository).to receive(:gitaly_operation_client).and_raise('Something went wrong') + allow(repository).to receive(:gitaly_operation_client).and_raise(exception) end it 'saves a generic error message' do - subject.execute(merge_request) + service.execute(merge_request) expect(merge_request.reload.merge_error).to eq(described_class::REBASE_ERROR) end @@ -86,6 +89,18 @@ describe MergeRequests::RebaseService do expect(service.execute(merge_request)).to match(status: :error, message: described_class::REBASE_ERROR) end + + it 'logs the error' do + expect(service).to receive(:log_error).with(exception: exception, message: described_class::REBASE_ERROR, save_message_on_model: true).and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_exception).with(exception, + class: described_class.to_s, + merge_request: merge_request_ref, + merge_request_id: merge_request.id, + message: described_class::REBASE_ERROR, + save_message_on_model: true).and_call_original + + service.execute(merge_request) + end end context 'with git command failure' do diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 4f052fa3edb..94e65d895ac 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -94,6 +94,31 @@ describe MergeRequests::RefreshService do expect(@fork_build_failed_todo).to be_done end + context 'when a merge error exists' do + let(:error_message) { 'This is a merge error' } + + before do + @merge_request = create(:merge_request, + source_project: @project, + source_branch: 'feature', + target_branch: 'master', + target_project: @project, + merge_error: error_message) + end + + it 'clears merge errors when pushing to the source branch' do + expect { refresh_service.execute(@oldrev, @newrev, 'refs/heads/feature') } + .to change { @merge_request.reload.merge_error } + .from(error_message) + .to(nil) + end + + it 'does not clear merge errors when pushing to the target branch' do + expect { refresh_service.execute(@oldrev, @newrev, 'refs/heads/master') } + .not_to change { @merge_request.reload.merge_error } + end + end + it 'reloads source branch MRs memoization' do refresh_service.execute(@oldrev, @newrev, 'refs/heads/master') @@ -209,19 +234,6 @@ describe MergeRequests::RefreshService do end end - context 'when ci_use_merge_request_ref feature flag is false' do - before do - stub_feature_flags(ci_use_merge_request_ref: false) - end - - it 'create legacy detached merge request pipeline for non-fork merge request' do - subject - - expect(@merge_request.pipelines_for_merge_request.first) - .to be_legacy_detached_merge_request_pipeline - end - end - context "when branch pipeline was created before a detaced merge request pipeline has been created" do before do create(:ci_pipeline, project: @merge_request.source_project, @@ -623,7 +635,7 @@ describe MergeRequests::RefreshService do references: [issue], author_name: commit_author.name, author_email: commit_author.email, - committed_date: Time.now + committed_date: Time.current ) allow_any_instance_of(MergeRequest).to receive(:commits).and_return(CommitCollection.new(@project, [commit], 'feature')) diff --git a/spec/services/merge_requests/squash_service_spec.rb b/spec/services/merge_requests/squash_service_spec.rb index cb278eec692..a53314ed737 100644 --- a/spec/services/merge_requests/squash_service_spec.rb +++ b/spec/services/merge_requests/squash_service_spec.rb @@ -141,15 +141,14 @@ describe MergeRequests::SquashService do let(:merge_request) { merge_request_with_only_new_files } let(:error) { 'A test error' } - context 'with gitaly enabled' do + context 'with an error in Gitaly UserSquash RPC' do before do allow(repository.gitaly_operation_client).to receive(:user_squash) .and_raise(Gitlab::Git::Repository::GitError, error) end - it 'logs the stage and output' do - expect(service).to receive(:log_error).with(log_error) - expect(service).to receive(:log_error).with(error) + it 'logs the error' do + expect(service).to receive(:log_error).with(exception: an_instance_of(Gitlab::Git::Repository::GitError), message: 'Failed to squash merge request') service.execute end @@ -158,19 +157,42 @@ describe MergeRequests::SquashService do expect(service.execute).to match(status: :error, message: a_string_including('squash')) end end + + context 'with an error in squash in progress check' do + before do + allow(repository).to receive(:squash_in_progress?) + .and_raise(Gitlab::Git::Repository::GitError, error) + end + + it 'logs the stage and output' do + expect(service).to receive(:log_error).with(exception: an_instance_of(Gitlab::Git::Repository::GitError), message: 'Failed to check squash in progress') + + service.execute + end + + it 'returns an error' do + expect(service.execute).to match(status: :error, message: 'An error occurred while checking whether another squash is in progress.') + end + end end context 'when any other exception is thrown' do let(:merge_request) { merge_request_with_only_new_files } - let(:error) { 'A test error' } + let(:merge_request_ref) { merge_request.to_reference(full: true) } + let(:exception) { RuntimeError.new('A test error') } before do - allow(merge_request.target_project.repository).to receive(:squash).and_raise(error) + allow(merge_request.target_project.repository).to receive(:squash).and_raise(exception) end - it 'logs the MR reference and exception' do - expect(service).to receive(:log_error).with(a_string_including("#{project.full_path}#{merge_request.to_reference}")) - expect(service).to receive(:log_error).with(error) + it 'logs the error' do + expect(service).to receive(:log_error).with(exception: exception, message: 'Failed to squash merge request').and_call_original + expect(Gitlab::ErrorTracking).to receive(:track_exception).with(exception, + class: described_class.to_s, + merge_request: merge_request_ref, + merge_request_id: merge_request.id, + message: 'Failed to squash merge request', + save_message_on_model: false).and_call_original service.execute end diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index 8c1800c495f..2b934b24757 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -92,6 +92,7 @@ describe MergeRequests::UpdateService, :mailer do labels: [], mentioned_users: [user2], assignees: [user3], + milestone: nil, total_time_spent: 0, description: "FYI #{user2.to_reference}" } @@ -452,7 +453,7 @@ describe MergeRequests::UpdateService, :mailer do end it 'updates updated_at' do - expect(merge_request.reload.updated_at).to be > Time.now + expect(merge_request.reload.updated_at).to be > Time.current end end |