summaryrefslogtreecommitdiff
path: root/spec/services/issues
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:07 +0000
commit2a040e2655fe0a99df61ad0a7bd0c27e68af0c38 (patch)
treea245cd0d6dd10f185e2fd098e371adc1ea03b72b /spec/services/issues
parenta53d2c37c4934f564caa94543dd4cf5af1703e2d (diff)
downloadgitlab-ce-2a040e2655fe0a99df61ad0a7bd0c27e68af0c38.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/issues')
-rw-r--r--spec/services/issues/close_service_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb
index dce62d1d20e..eb3b1d7c754 100644
--- a/spec/services/issues/close_service_spec.rb
+++ b/spec/services/issues/close_service_spec.rb
@@ -98,6 +98,53 @@ describe Issues::CloseService do
expect(body_text).not_to include(closing_merge_request.to_reference)
end
end
+
+ context 'updating `metrics.first_mentioned_in_commit_at`' do
+ subject { described_class.new(project, user).close_issue(issue, closed_via: closing_merge_request) }
+
+ context 'when `metrics.first_mentioned_in_commit_at` is not set' do
+ it 'uses the first commit timestamp' do
+ expected = closing_merge_request.commits.first.date
+
+ subject
+
+ expect(issue.metrics.first_mentioned_in_commit_at).to eq(expected)
+ end
+ end
+
+ context 'when `metrics.first_mentioned_in_commit_at` is already set' do
+ before do
+ issue.metrics.update!(first_mentioned_in_commit_at: Time.now)
+ end
+
+ it 'does not update the metrics' do
+ expect { subject }.not_to change { issue.metrics.first_mentioned_in_commit_at }
+ end
+ end
+
+ context 'when merge request has no commits' do
+ let(:closing_merge_request) { create(:merge_request, :without_diffs, source_project: project) }
+
+ it 'does not update the metrics' do
+ subject
+
+ expect(issue.metrics.first_mentioned_in_commit_at).to be_nil
+ end
+ end
+
+ context 'when `store_first_mentioned_in_commit_on_issue_close` feature flag is off' do
+ before do
+ stub_feature_flags(store_first_mentioned_in_commit_on_issue_close: { enabled: false, thing: issue.project })
+ end
+
+ it 'does not update the metrics' do
+ subject
+
+ expect(described_class).not_to receive(:store_first_mentioned_in_commit_at)
+ expect(issue.metrics.first_mentioned_in_commit_at).to be_nil
+ end
+ end
+ end
end
context "closed by a commit", :sidekiq_might_not_need_inline do