diff options
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb')
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb | 66 |
1 files changed, 56 insertions, 10 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 index 664009f140f..2242895f8ea 100644 --- a/spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/group_stage_summary_spec.rb @@ -20,7 +20,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "finds the number of issues created after it" do - expect(subject.first[:value]).to eq(2) + expect(subject.first[:value]).to eq('2') end context 'with subgroups' do @@ -29,7 +29,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "finds issues from them" do - expect(subject.first[:value]).to eq(3) + expect(subject.first[:value]).to eq('3') end end @@ -41,7 +41,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do 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) + expect(subject.first[:value]).to eq('2') end end @@ -49,7 +49,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary 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) + expect(subject.first[:value]).to eq('2') end end end @@ -62,7 +62,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "doesn't find issues from them" do - expect(subject.first[:value]).to eq(2) + expect(subject.first[:value]).to eq('2') end end end @@ -77,7 +77,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "finds the number of deploys made created after it" do - expect(subject.second[:value]).to eq(2) + expect(subject.second[:value]).to eq('2') end context 'with subgroups' do @@ -88,7 +88,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "finds deploys from them" do - expect(subject.second[:value]).to eq(3) + expect(subject.second[:value]).to eq('3') end end @@ -102,7 +102,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do 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) + expect(subject.second[:value]).to eq('2') end end @@ -110,7 +110,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary 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) + expect(subject.second[:value]).to eq('2') end end end @@ -123,7 +123,53 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do end it "doesn't find deploys from them" do - expect(subject.second[:value]).to eq(0) + 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 |