debian-mirror-gitlab/spec/models/issue/metrics_spec.rb

58 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Issue::Metrics do
let(:project) { create(:project) }
2016-09-29 09:46:39 +05:30
subject { create(:issue, project: project) }
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
time = Time.now
2019-03-13 22:55:13 +05:30
Timecop.freeze(time) { subject.update(milestone: create(:milestone, project: project)) }
2016-09-29 09:46:39 +05:30
metrics = subject.metrics
expect(metrics).to be_present
2016-11-03 12:29:30 +05:30
expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
2016-09-29 09:46:39 +05:30
end
it "does not record the second time an issue is associated with a milestone" do
time = Time.now
2019-03-13 22:55:13 +05:30
Timecop.freeze(time) { subject.update(milestone: create(:milestone, project: project)) }
2016-09-29 09:46:39 +05:30
Timecop.freeze(time + 2.hours) { subject.update(milestone: nil) }
2019-03-13 22:55:13 +05:30
Timecop.freeze(time + 6.hours) { subject.update(milestone: create(:milestone, project: project)) }
2016-09-29 09:46:39 +05:30
metrics = subject.metrics
expect(metrics).to be_present
2016-11-03 12:29:30 +05:30
expect(metrics.first_associated_with_milestone_at).to be_like_time(time)
2016-09-29 09:46:39 +05:30
end
end
context "list labels" do
it "records the first time an issue is associated with a list label" do
2019-09-30 21:07:59 +05:30
list_label = create(:list).label
2016-09-29 09:46:39 +05:30
time = Time.now
Timecop.freeze(time) { subject.update(label_ids: [list_label.id]) }
metrics = subject.metrics
expect(metrics).to be_present
2016-11-03 12:29:30 +05:30
expect(metrics.first_added_to_board_at).to be_like_time(time)
2016-09-29 09:46:39 +05:30
end
it "does not record the second time an issue is associated with a list label" do
time = Time.now
2019-09-30 21:07:59 +05:30
first_list_label = create(:list).label
2016-09-29 09:46:39 +05:30
Timecop.freeze(time) { subject.update(label_ids: [first_list_label.id]) }
2019-09-30 21:07:59 +05:30
second_list_label = create(:list).label
2016-09-29 09:46:39 +05:30
Timecop.freeze(time + 5.hours) { subject.update(label_ids: [second_list_label.id]) }
metrics = subject.metrics
expect(metrics).to be_present
2016-11-03 12:29:30 +05:30
expect(metrics.first_added_to_board_at).to be_like_time(time)
2016-09-29 09:46:39 +05:30
end
end
end
end