diff options
author | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-09 18:32:42 +0300 |
---|---|---|
committer | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-16 21:51:19 +0300 |
commit | eef63813ea6a9585941be5f079104604d779d440 (patch) | |
tree | c8f821cbcd8750978e781c065847839d13332bab /spec/workers/process_commit_worker_spec.rb | |
parent | dfb14e4d22aa91d9d3fbcee5c7e44ae61bf18c51 (diff) |
stop ProcessCommitWorker from processing MR merge commit
When a merge request is merged, it creates a commit with the
description of the MR, which may contain references and issue
closing references. As this will be handled in the PostMergeService
anyways, let's ignore merge commit generated from a MR.
Diffstat (limited to 'spec/workers/process_commit_worker_spec.rb')
-rw-r--r-- | spec/workers/process_commit_worker_spec.rb | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index 24f8ca67594..cd6918470a0 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -20,6 +20,32 @@ describe ProcessCommitWorker do worker.perform(project.id, -1, commit.to_hash) end + context 'when commit is a merge request merge commit' do + let(:merge_request) do + create(:merge_request, + description: "Closes #{issue.to_reference}", + source_branch: 'feature-merged', + target_branch: 'master', + source_project: project) + end + + let(:commit) do + project.repository.create_branch('feature-merged', 'feature') + + sha = project.repository.merge(user, + merge_request.diff_head_sha, + merge_request, + "Closes #{issue.to_reference}") + project.repository.commit(sha) + end + + it 'does not process the commit' do + expect(worker).not_to receive(:close_issues) + + worker.perform(project.id, user.id, commit.to_hash) + end + end + it 'processes the commit message' do expect(worker).to receive(:process_commit_message).and_call_original @@ -49,10 +75,10 @@ describe ProcessCommitWorker do context 'when pushing to the default branch' do it 'closes issues that should be closed per the commit message' do allow(commit).to receive(:safe_message) - .and_return("Closes #{issue.to_reference}") + .and_return("Closes #{issue.to_reference}") expect(worker).to receive(:close_issues) - .with(project, user, user, commit, [issue]) + .with(project, user, user, commit, [issue]) worker.process_commit_message(project, commit, user, user, true) end @@ -61,7 +87,7 @@ describe ProcessCommitWorker do context 'when pushing to a non-default branch' do it 'does not close any issues' do allow(commit).to receive(:safe_message) - .and_return("Closes #{issue.to_reference}") + .and_return("Closes #{issue.to_reference}") expect(worker).not_to receive(:close_issues) @@ -103,7 +129,7 @@ describe ProcessCommitWorker do describe '#update_issue_metrics' do it 'updates any existing issue metrics' do allow(commit).to receive(:safe_message) - .and_return("Closes #{issue.to_reference}") + .and_return("Closes #{issue.to_reference}") worker.update_issue_metrics(commit, user) @@ -114,7 +140,7 @@ describe ProcessCommitWorker do it "doesn't execute any queries with false conditions" do allow(commit).to receive(:safe_message) - .and_return("Lorem Ipsum") + .and_return("Lorem Ipsum") expect { worker.update_issue_metrics(commit, user) }.not_to make_queries_matching(/WHERE (?:1=0|0=1)/) end @@ -129,7 +155,7 @@ describe ProcessCommitWorker do it 'parses date strings into Time instances' do commit = worker - .build_commit(project, id: '123', authored_date: Time.now.to_s) + .build_commit(project, id: '123', authored_date: Time.now.to_s) expect(commit.authored_date).to be_an_instance_of(Time) end |