Commit c1dfca96 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'sh-fix-issue-197464' into 'master'

Fix analytics tracking for new merge request notes

Closes #197464

See merge request gitlab-org/gitlab!23273
parents 58ff3704 30de0eb5
---
title: Fix analytics tracking for new merge request notes
merge_request: 23273
author:
type: fixed
......@@ -22,9 +22,11 @@ module Analytics
def execute(force: false)
merge_requests.each do |mr|
next if !force && mr.metrics.first_comment_at
metrics = mr.ensure_metrics
mr.metrics.update!(first_comment_at: ProductivityCalculator.new(mr).first_comment_at)
next if !force && metrics.first_comment_at
metrics.update!(first_comment_at: ProductivityCalculator.new(mr).first_comment_at)
end
end
......
......@@ -25,6 +25,19 @@ describe Analytics::RefreshCommentsData do
end.to change { noteable.metrics.first_comment_at }.from(nil).to(be_like_time(note.created_at))
end
context 'when no merge request metric is present' do
before do
noteable.metrics.destroy
noteable.reload
end
it 'creates a new metric and updates the first_comment_at' do
subject.execute
expect(noteable.metrics.reload.first_comment_at).to(be_like_time(note.created_at))
end
end
context 'and first_comment_at is already filled' do
before do
noteable.metrics.update(first_comment_at: 3.days.ago.beginning_of_day)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment