summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/cycle_analytics
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/lib/gitlab/cycle_analytics
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics')
-rw-r--r--spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb176
-rw-r--r--spec/lib/gitlab/cycle_analytics/summary/value_spec.rb33
2 files changed, 33 insertions, 176 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb b/spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb
deleted file mode 100644
index 2242895f8ea..00000000000
--- a/spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb
+++ /dev/null
@@ -1,176 +0,0 @@
-# frozen_string_literal: true
-require 'spec_helper'
-
-describe Gitlab::CycleAnalytics::GroupStageSummary do
- let(:group) { create(:group) }
- let(:project) { create(:project, :repository, namespace: group) }
- let(:project_2) { create(:project, :repository, namespace: group) }
- let(:from) { 1.day.ago }
- let(:user) { create(:user, :admin) }
-
- subject { described_class.new(group, options: { from: Time.now, current_user: user }).data }
-
- describe "#new_issues" do
- context 'with from date' do
- before do
- Timecop.freeze(5.days.ago) { create(:issue, project: project) }
- Timecop.freeze(5.days.ago) { create(:issue, project: project_2) }
- Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
- Timecop.freeze(5.days.from_now) { create(:issue, project: project_2) }
- end
-
- it "finds the number of issues created after it" do
- expect(subject.first[:value]).to eq('2')
- end
-
- context 'with subgroups' do
- before do
- Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group, parent: group))) }
- end
-
- it "finds issues from them" do
- expect(subject.first[:value]).to eq('3')
- end
- end
-
- context 'with projects specified in options' do
- before do
- Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: group)) }
- end
-
- subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
-
- it 'finds issues from those projects' do
- expect(subject.first[:value]).to eq('2')
- end
- end
-
- context 'when `from` and `to` parameters are provided' do
- subject { described_class.new(group, options: { from: 10.days.ago, to: Time.now, current_user: user }).data }
-
- it 'finds issues from 5 days ago' do
- expect(subject.first[:value]).to eq('2')
- end
- end
- end
-
- context 'with other projects' do
- before do
- Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group))) }
- Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
- Timecop.freeze(5.days.from_now) { create(:issue, project: project_2) }
- end
-
- it "doesn't find issues from them" do
- expect(subject.first[:value]).to eq('2')
- end
- end
- end
-
- describe "#deploys" do
- context 'with from date' do
- before do
- Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
- Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
- Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project_2) }
- Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project_2) }
- end
-
- it "finds the number of deploys made created after it" do
- expect(subject.second[:value]).to eq('2')
- end
-
- context 'with subgroups' do
- before do
- Timecop.freeze(5.days.from_now) do
- create(:deployment, :success, project: create(:project, :repository, namespace: create(:group, parent: group)))
- end
- end
-
- it "finds deploys from them" do
- expect(subject.second[:value]).to eq('3')
- end
- end
-
- context 'with projects specified in options' do
- before do
- Timecop.freeze(5.days.from_now) do
- create(:deployment, :success, project: create(:project, :repository, namespace: group, name: 'not_applicable'))
- end
- end
-
- subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
-
- it 'shows deploys from those projects' do
- expect(subject.second[:value]).to eq('2')
- end
- end
-
- context 'when `from` and `to` parameters are provided' do
- subject { described_class.new(group, options: { from: 10.days.ago, to: Time.now, current_user: user }).data }
-
- it 'finds deployments from 5 days ago' do
- expect(subject.second[:value]).to eq('2')
- end
- end
- end
-
- context 'with other projects' do
- before do
- Timecop.freeze(5.days.from_now) do
- create(:deployment, :success, project: create(:project, :repository, namespace: create(:group)))
- end
- end
-
- it "doesn't find deploys from them" do
- expect(subject.second[:value]).to eq('-')
- end
- end
- end
-
- describe '#deployment_frequency' do
- let(:from) { 6.days.ago }
- let(:to) { nil }
-
- subject do
- described_class.new(group, options: {
- from: from,
- to: to,
- current_user: user
- }).data.third
- end
-
- it 'includes the unit: `per day`' do
- expect(subject[:unit]).to eq(_('per day'))
- end
-
- before do
- Timecop.freeze(5.days.ago) do
- create(:deployment, :success, project: project)
- end
- end
-
- context 'when `to` is nil' do
- it 'includes range until now' do
- # 1 deployment over 7 days
- expect(subject[:value]).to eq('0.1')
- end
- end
-
- context 'when `to` is given' do
- let(:from) { 10.days.ago }
- let(:to) { 10.days.from_now }
-
- before do
- Timecop.freeze(5.days.from_now) do
- create(:deployment, :success, project: project)
- end
- end
-
- it 'returns deployment frequency within `from` and `to` range' do
- # 2 deployments over 20 days
- expect(subject[:value]).to eq('0.1')
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/cycle_analytics/summary/value_spec.rb b/spec/lib/gitlab/cycle_analytics/summary/value_spec.rb
new file mode 100644
index 00000000000..d9bdfa92a04
--- /dev/null
+++ b/spec/lib/gitlab/cycle_analytics/summary/value_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::CycleAnalytics::Summary::Value do
+ describe Gitlab::CycleAnalytics::Summary::Value::None do
+ it 'returns `-`' do
+ expect(described_class.new.to_s).to eq('-')
+ end
+ end
+
+ describe Gitlab::CycleAnalytics::Summary::Value::Numeric do
+ it 'returns the string representation of the number' do
+ expect(described_class.new(3.2).to_s).to eq('3.2')
+ end
+ end
+
+ describe Gitlab::CycleAnalytics::Summary::Value::PrettyNumeric do
+ describe '#to_s' do
+ it 'returns `-` when the number is 0' do
+ expect(described_class.new(0).to_s).to eq('-')
+ end
+
+ it 'returns `-` when the number is nil' do
+ expect(described_class.new(nil).to_s).to eq('-')
+ end
+
+ it 'returns the string representation of the number' do
+ expect(described_class.new(100).to_s).to eq('100')
+ end
+ end
+ end
+end