2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-19 07:26:25 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Issue::Metrics do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-09-19 07:26:25 +00:00
|
|
|
|
|
|
|
subject { create(:issue, project: project) }
|
|
|
|
|
2019-12-04 18:08:46 +00:00
|
|
|
describe '.for_issues' do
|
|
|
|
subject(:scope) { described_class.for_issues([issue1, issue2]) }
|
|
|
|
|
|
|
|
let(:issue1) { create(:issue) }
|
|
|
|
let(:issue2) { create(:issue) }
|
|
|
|
|
|
|
|
it 'returns metrics associated with given issues' do
|
|
|
|
create(:issue)
|
|
|
|
|
|
|
|
expect(scope).to match_array([issue1.metrics, issue2.metrics])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.with_first_mention_not_earlier_than' do
|
|
|
|
subject(:scope) { described_class.with_first_mention_not_earlier_than(timestamp) }
|
|
|
|
|
2020-05-22 09:08:09 +00:00
|
|
|
let(:timestamp) { DateTime.current }
|
2019-12-04 18:08:46 +00:00
|
|
|
|
|
|
|
it 'returns metrics without mentioning in commit or with mentioning after given timestamp' do
|
|
|
|
issue1 = create(:issue)
|
|
|
|
issue2 = create(:issue).tap { |i| i.metrics.update!(first_mentioned_in_commit_at: timestamp + 1.day) }
|
|
|
|
create(:issue).tap { |i| i.metrics.update!(first_mentioned_in_commit_at: timestamp - 1.day) }
|
|
|
|
|
|
|
|
expect(scope).to match_array([issue1.metrics, issue2.metrics])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-19 07:26:25 +00:00
|
|
|
describe "when recording the default set of issue metrics on issue save" do
|
|
|
|
context "milestones" do
|
|
|
|
it "records the first time an issue is associated with a milestone" do
|
2020-05-22 09:08:09 +00:00
|
|
|
time = Time.current
|
2020-10-02 12:09:03 +00:00
|
|
|
travel_to(time) { subject.update(milestone: create(:milestone, project: project)) }
|
2016-09-19 07:26:25 +00:00
|
|
|
metrics = subject.metrics
|
|
|
|
|
|
|
|
expect(metrics).to be_present
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
|
2016-09-19 07:26:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not record the second time an issue is associated with a milestone" do
|
2020-05-22 09:08:09 +00:00
|
|
|
time = Time.current
|
2020-10-02 12:09:03 +00:00
|
|
|
travel_to(time) { subject.update(milestone: create(:milestone, project: project)) }
|
|
|
|
travel_to(time + 2.hours) { subject.update(milestone: nil) }
|
|
|
|
travel_to(time + 6.hours) { subject.update(milestone: create(:milestone, project: project)) }
|
2016-09-19 07:26:25 +00:00
|
|
|
metrics = subject.metrics
|
|
|
|
|
|
|
|
expect(metrics).to be_present
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
|
2016-09-19 07:26:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "list labels" do
|
|
|
|
it "records the first time an issue is associated with a list label" do
|
2019-06-25 17:54:42 +00:00
|
|
|
list_label = create(:list).label
|
2020-05-22 09:08:09 +00:00
|
|
|
time = Time.current
|
2020-10-02 12:09:03 +00:00
|
|
|
travel_to(time) { subject.update(label_ids: [list_label.id]) }
|
2016-09-19 07:26:25 +00:00
|
|
|
metrics = subject.metrics
|
|
|
|
|
|
|
|
expect(metrics).to be_present
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(metrics.first_added_to_board_at).to be_like_time(time)
|
2016-09-19 07:26:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not record the second time an issue is associated with a list label" do
|
2020-05-22 09:08:09 +00:00
|
|
|
time = Time.current
|
2019-06-25 17:54:42 +00:00
|
|
|
first_list_label = create(:list).label
|
2020-10-02 12:09:03 +00:00
|
|
|
travel_to(time) { subject.update(label_ids: [first_list_label.id]) }
|
2019-06-25 17:54:42 +00:00
|
|
|
second_list_label = create(:list).label
|
2020-10-02 12:09:03 +00:00
|
|
|
travel_to(time + 5.hours) { subject.update(label_ids: [second_list_label.id]) }
|
2016-09-19 07:26:25 +00:00
|
|
|
metrics = subject.metrics
|
|
|
|
|
|
|
|
expect(metrics).to be_present
|
2016-10-17 12:40:02 +00:00
|
|
|
expect(metrics.first_added_to_board_at).to be_like_time(time)
|
2016-09-19 07:26:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|