Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issue_spec.rb « cycle_analytics « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ba66c99631cb4ab5b09976c47fc7f7e26b769531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'spec_helper'

describe 'CycleAnalytics#issue', models: true do
  let(:project) { create(:project) }
  subject { CycleAnalytics.new }

  context "when calculating the median of times between:
               start: issue created_at
                 end: milestone first added to issue
                      OR
                      list-label first added to issue
           " do
    context "when a milestone is added to the issue" do
      it "calculates the median of available durations" do
        start_and_end_times = Array.new(5) do
          start_time = Time.now
          end_time = rand(1..10).days.from_now

          milestone = create(:milestone, project: project)
          issue = Timecop.freeze(start_time) { create(:issue, project: project) }
          Timecop.freeze(end_time) { issue.update(milestone: milestone) }

          [start_time, end_time]
        end

        median_start_time, median_end_time = start_and_end_times[2]
        expect(subject.issue).to eq(median_end_time - median_start_time)
      end
    end

    context "when a label is added to the issue" do
      it "calculates the median of available durations when the label is a list-label" do
        start_and_end_times = Array.new(5) do
          start_time = Time.now
          end_time = rand(1..10).days.from_now

          list_label = create(:label, lists: [create(:list)])
          issue = Timecop.freeze(start_time) { create(:issue, project: project) }
          Timecop.freeze(end_time) { issue.update(label_ids: [list_label.id]) }

          [start_time, end_time]
        end

        median_start_time, median_end_time = start_and_end_times[2]
        expect(subject.issue).to eq(median_end_time - median_start_time)
      end

      it "does not make a calculation for regular labels" do
        5.times do
          start_time = Time.now
          end_time = rand(1..10).days.from_now

          regular_label = create(:label)
          issue = Timecop.freeze(start_time) { create(:issue, project: project) }
          Timecop.freeze(end_time) { issue.update(label_ids: [regular_label.id]) }

          [start_time, end_time]
        end

        expect(subject.issue).to be_nil
      end
    end

    context "when a milestone and list-label are both added to the issue" do
      it "uses the time the milestone was added as the 'end time'" do
        start_time = Time.now
        milestone_add_time = rand(1..10).days.from_now
        list_label_add_time = rand(1..10).days.from_now

        milestone = create(:milestone, project: project)
        list_label = create(:label, lists: [create(:list)])
        issue = Timecop.freeze(start_time) { create(:issue, project: project) }
        Timecop.freeze(milestone_add_time) { issue.update(milestone: milestone) }
        Timecop.freeze(list_label_add_time) { issue.update(label_ids: [list_label.id]) }

        expect(subject.issue).to eq(milestone_add_time - start_time)
      end
    end
  end
end