diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-04 21:08:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-04 21:08:46 +0300 |
commit | b41cd8cb92d53454b2b160ba922d33801933a9cf (patch) | |
tree | 3519da8856f8bf12ce9e75248e5ecb9ed4eacf14 /spec/workers/process_commit_worker_spec.rb | |
parent | 8d3aee3636da5181ae94d23b47c6794b5610ab01 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/process_commit_worker_spec.rb')
-rw-r--r-- | spec/workers/process_commit_worker_spec.rb | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index 99800135075..21c300af7ac 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -129,21 +129,54 @@ describe ProcessCommitWorker do end describe '#update_issue_metrics' do - it 'updates any existing issue metrics' do - allow(commit).to receive(:safe_message).and_return("Closes #{issue.to_reference}") + context 'when commit has issue reference' do + subject(:update_metrics_and_reload) do + -> { + worker.update_issue_metrics(commit, user) + issue.metrics.reload + } + end + + before do + allow(commit).to receive(:safe_message).and_return("Closes #{issue.to_reference}") + end - worker.update_issue_metrics(commit, user) + context 'when issue has no first_mentioned_in_commit_at set' do + it 'updates issue metrics' do + expect(update_metrics_and_reload) + .to change { issue.metrics.first_mentioned_in_commit_at }.to(commit.committed_date) + end + end - metric = Issue::Metrics.first + context 'when issue has first_mentioned_in_commit_at earlier than given committed_date' do + before do + issue.metrics.update(first_mentioned_in_commit_at: commit.committed_date - 1.day) + end - expect(metric.first_mentioned_in_commit_at).to eq(commit.committed_date) + it "doesn't update issue metrics" do + expect(update_metrics_and_reload).not_to change { issue.metrics.first_mentioned_in_commit_at } + end + end + + context 'when issue has first_mentioned_in_commit_at later than given committed_date' do + before do + issue.metrics.update(first_mentioned_in_commit_at: commit.committed_date + 1.day) + end + + it "doesn't update issue metrics" do + expect(update_metrics_and_reload) + .to change { issue.metrics.first_mentioned_in_commit_at }.to(commit.committed_date) + end + end end - it "doesn't execute any queries with false conditions" do - allow(commit).to receive(:safe_message).and_return("Lorem Ipsum") + context 'when commit has no issue references' do + it "doesn't execute any queries with false conditions" do + allow(commit).to receive(:safe_message).and_return("Lorem Ipsum") - expect { worker.update_issue_metrics(commit, user) } - .not_to make_queries_matching(/WHERE (?:1=0|0=1)/) + expect { worker.update_issue_metrics(commit, user) } + .not_to make_queries_matching(/WHERE (?:1=0|0=1)/) + end end end |