diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 09:07:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 09:07:50 +0300 |
commit | e50050a8756a20b6aa118edbad3369674e4c63ba (patch) | |
tree | 0f9ae83c168b01707753e066294f7b55aa0968a5 /spec/services/merge_requests | |
parent | 1dffba3bd853076efc1107b2dd63e221e75a210c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/merge_requests')
-rw-r--r-- | spec/services/merge_requests/merge_service_spec.rb | 17 | ||||
-rw-r--r-- | spec/services/merge_requests/post_merge_service_spec.rb | 1 | ||||
-rw-r--r-- | spec/services/merge_requests/squash_service_spec.rb | 18 |
3 files changed, 35 insertions, 1 deletions
diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index fa7f745d8a0..2283f480895 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -47,6 +47,23 @@ describe MergeRequests::MergeService do expect(note.note).to include 'merged' end + it 'is idempotent' do + repository = project.repository + commit_count = repository.commit_count + merge_commit = merge_request.merge_commit.id + + # a first invocation of execute is performed on the before block + service.execute(merge_request) + + expect(merge_request.merge_error).to be_falsey + expect(merge_request).to be_valid + expect(merge_request).to be_merged + + expect(repository.commits_by(oids: [merge_commit]).size).to eq(1) + expect(repository.commit_count).to eq(commit_count) + expect(merge_request.in_progress_merge_commit_sha).to be_nil + end + context 'when squashing' do let(:merge_params) do { commit_message: 'Merge commit message', diff --git a/spec/services/merge_requests/post_merge_service_spec.rb b/spec/services/merge_requests/post_merge_service_spec.rb index fff6ddf3928..06735d25ad5 100644 --- a/spec/services/merge_requests/post_merge_service_spec.rb +++ b/spec/services/merge_requests/post_merge_service_spec.rb @@ -17,7 +17,6 @@ describe MergeRequests::PostMergeService do it 'refreshes the number of open merge requests for a valid MR', :use_clean_rails_memory_store_caching do # Cache the counter before the MR changed state. project.open_merge_requests_count - merge_request.update!(state: 'merged') service = described_class.new(project, user, {}) diff --git a/spec/services/merge_requests/squash_service_spec.rb b/spec/services/merge_requests/squash_service_spec.rb index cb278eec692..4636f26bb16 100644 --- a/spec/services/merge_requests/squash_service_spec.rb +++ b/spec/services/merge_requests/squash_service_spec.rb @@ -137,6 +137,24 @@ describe MergeRequests::SquashService do include_examples 'the squash succeeds' end + context 'when the merge request has already been merged' do + let(:merge_request) { merge_request_with_one_commit } + + it 'checks the side-effects for multiple calls' do + merge_request.mark_as_merged + + expect(service).to be_idempotent + expect { IdempotentWorkerHelper::WORKER_EXEC_TIMES.times { service.execute } }.not_to raise_error + end + + it 'idempotently returns a success' do + merge_request.mark_as_merged + result = service.execute + + expect(result).to match(status: :success, squash_sha: merge_request.diff_head_sha) + end + end + context 'git errors' do let(:merge_request) { merge_request_with_only_new_files } let(:error) { 'A test error' } |