summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb')
-rw-r--r--spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb84
1 files changed, 75 insertions, 9 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb b/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb
index 778c2f479b5..8f9dac6d281 100644
--- a/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb
@@ -4,52 +4,98 @@ require 'spec_helper'
describe Gitlab::CycleAnalytics::StageSummary do
let(:project) { create(:project, :repository) }
- let(:from) { 1.day.ago }
+ let(:options) { { from: 1.day.ago, current_user: user } }
let(:user) { create(:user, :admin) }
- subject { described_class.new(project, from: Time.now, current_user: user).data }
+ let(:stage_summary) { described_class.new(project, options).data }
describe "#new_issues" do
+ subject { stage_summary.first[:value] }
+
it "finds the number of issues created after the 'from date'" do
Timecop.freeze(5.days.ago) { create(:issue, project: project) }
Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
- expect(subject.first[:value]).to eq(1)
+ expect(subject).to eq(1)
end
it "doesn't find issues from other projects" do
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project)) }
- expect(subject.first[:value]).to eq(0)
+ expect(subject).to eq(0)
+ end
+
+ context 'when `to` parameter is given' do
+ before do
+ Timecop.freeze(5.days.ago) { create(:issue, project: project) }
+ Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
+ end
+
+ it "doesn't find any record" do
+ options[:to] = Time.now
+
+ expect(subject).to eq(0)
+ end
+
+ it "finds records created between `from` and `to` range" do
+ options[:from] = 10.days.ago
+ options[:to] = 10.days.from_now
+
+ expect(subject).to eq(2)
+ end
end
end
describe "#commits" do
+ subject { stage_summary.second[:value] }
+
it "finds the number of commits created after the 'from date'" do
Timecop.freeze(5.days.ago) { create_commit("Test message", project, user, 'master') }
Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master') }
- expect(subject.second[:value]).to eq(1)
+ expect(subject).to eq(1)
end
it "doesn't find commits from other projects" do
Timecop.freeze(5.days.from_now) { create_commit("Test message", create(:project, :repository), user, 'master') }
- expect(subject.second[:value]).to eq(0)
+ expect(subject).to eq(0)
end
it "finds a large (> 100) snumber of commits if present" do
Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master', count: 100) }
- expect(subject.second[:value]).to eq(100)
+ expect(subject).to eq(100)
+ end
+
+ context 'when `to` parameter is given' do
+ before do
+ Timecop.freeze(5.days.ago) { create_commit("Test message", project, user, 'master') }
+ Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master') }
+ end
+
+ it "doesn't find any record" do
+ options[:to] = Time.now
+
+ expect(subject).to eq(0)
+ end
+
+ it "finds records created between `from` and `to` range" do
+ options[:from] = 10.days.ago
+ options[:to] = 10.days.from_now
+
+ expect(subject).to eq(2)
+ end
end
end
describe "#deploys" do
+ subject { stage_summary.third[:value] }
+
it "finds the number of deploys made created after the 'from date'" do
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
- expect(subject.third[:value]).to eq(1)
+ expect(subject).to eq(1)
end
it "doesn't find commits from other projects" do
@@ -57,7 +103,27 @@ describe Gitlab::CycleAnalytics::StageSummary do
create(:deployment, :success, project: create(:project, :repository))
end
- expect(subject.third[:value]).to eq(0)
+ expect(subject).to eq(0)
+ end
+
+ context 'when `to` parameter is given' do
+ before do
+ Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
+ Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
+ end
+
+ it "doesn't find any record" do
+ options[:to] = Time.now
+
+ expect(subject).to eq(0)
+ end
+
+ it "finds records created between `from` and `to` range" do
+ options[:from] = 10.days.ago
+ options[:to] = 10.days.from_now
+
+ expect(subject).to eq(2)
+ end
end
end
end