diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-08 00:07:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-08 00:07:54 +0300 |
commit | 8c8b94e7116fa478ad490bd14c09565d23097f57 (patch) | |
tree | 9e4637aa0fe498a5523c86932b87ff691ec72af6 /spec/lib/gitlab/cycle_analytics | |
parent | eadb77d89f5f7d445bfd326f18873168f4719f12 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics')
7 files changed, 115 insertions, 14 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb index dd1d9ac0f16..6959778661b 100644 --- a/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/code_stage_spec.rb @@ -12,7 +12,8 @@ describe Gitlab::CycleAnalytics::CodeStage do let(:issue_3) { create(:issue, project: project, created_at: 60.minutes.ago) } let(:mr_1) { create(:merge_request, source_project: project, created_at: 15.minutes.ago) } let(:mr_2) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'A') } - let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: project.creator, project: project }) } + let(:stage_options) { { from: 2.days.ago, current_user: project.creator, project: project } } + let(:stage) { described_class.new(options: stage_options) } before do issue_1.metrics.update!(first_associated_with_milestone_at: 60.minutes.ago, first_mentioned_in_commit_at: 45.minutes.ago) @@ -33,6 +34,8 @@ describe Gitlab::CycleAnalytics::CodeStage do it 'counts median from issues with metrics' do expect(stage.project_median).to eq(ISSUES_MEDIAN) end + + include_examples 'calculate #median with date range' end describe '#events' do diff --git a/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb index 4dd21239cde..b99debf8cac 100644 --- a/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb @@ -10,7 +10,8 @@ describe Gitlab::CycleAnalytics::IssueStage do let(:issue_2) { create(:issue, project: project, created_at: 60.minutes.ago) } let(:issue_3) { create(:issue, project: project, created_at: 30.minutes.ago) } let!(:issue_without_milestone) { create(:issue, project: project, created_at: 1.minute.ago) } - let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: project.creator, project: project }) } + let(:stage_options) { { from: 2.days.ago, current_user: project.creator, project: project } } + let(:stage) { described_class.new(options: stage_options) } before do issue_1.metrics.update!(first_associated_with_milestone_at: 60.minutes.ago ) @@ -28,6 +29,8 @@ describe Gitlab::CycleAnalytics::IssueStage do it 'counts median from issues with metrics' do expect(stage.project_median).to eq(ISSUES_MEDIAN) end + + include_examples 'calculate #median with date range' end describe '#events' do diff --git a/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb index 98d2593de66..60d180015c4 100644 --- a/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb @@ -10,7 +10,8 @@ describe Gitlab::CycleAnalytics::PlanStage do let!(:issue_2) { create(:issue, project: project, created_at: 60.minutes.ago) } let!(:issue_3) { create(:issue, project: project, created_at: 30.minutes.ago) } let!(:issue_without_milestone) { create(:issue, project: project, created_at: 1.minute.ago) } - let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: project.creator, project: project }) } + let(:stage_options) { { from: 2.days.ago, current_user: project.creator, project: project } } + let(:stage) { described_class.new(options: stage_options) } before do issue_1.metrics.update!(first_associated_with_milestone_at: 60.minutes.ago, first_mentioned_in_commit_at: 10.minutes.ago) @@ -28,6 +29,8 @@ describe Gitlab::CycleAnalytics::PlanStage do it 'counts median from issues with metrics' do expect(stage.project_median).to eq(ISSUES_MEDIAN) end + + include_examples 'calculate #median with date range' end describe '#events' do diff --git a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb index cf95741908f..b3a6c2c4239 100644 --- a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb @@ -32,3 +32,23 @@ shared_examples 'base stage' do expect(stage.events).not_to be_nil end end + +shared_examples 'calculate #median with date range' do + context 'when valid date range is given' do + before do + stage_options[:from] = 5.days.ago + stage_options[:to] = 5.days.from_now + end + + it { expect(stage.project_median).to eq(ISSUES_MEDIAN) } + end + + context 'when records are out of the date range' do + before do + stage_options[:from] = 2.years.ago + stage_options[:to] = 1.year.ago + end + + it { expect(stage.project_median).to eq(nil) } + end +end 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 diff --git a/spec/lib/gitlab/cycle_analytics/staging_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/staging_stage_spec.rb index bd64c4aca42..306b08a60e1 100644 --- a/spec/lib/gitlab/cycle_analytics/staging_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/staging_stage_spec.rb @@ -16,7 +16,8 @@ describe Gitlab::CycleAnalytics::StagingStage do let(:build_1) { create(:ci_build, project: project) } let(:build_2) { create(:ci_build, project: project) } - let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: project.creator, project: project }) } + let(:stage_options) { { from: 2.days.ago, current_user: project.creator, project: project } } + let(:stage) { described_class.new(options: stage_options) } before do mr_1.metrics.update!(merged_at: 80.minutes.ago, first_deployed_to_production_at: 50.minutes.ago, pipeline_id: build_1.commit_id) @@ -38,6 +39,8 @@ describe Gitlab::CycleAnalytics::StagingStage do it 'counts median from issues with metrics' do expect(stage.project_median).to eq(ISSUES_MEDIAN) end + + it_behaves_like 'calculate #median with date range' end describe '#events' do diff --git a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb index 9162686d17d..bbb53cefae7 100644 --- a/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/test_stage_spec.rb @@ -6,7 +6,8 @@ require 'lib/gitlab/cycle_analytics/shared_stage_spec' describe Gitlab::CycleAnalytics::TestStage do let(:stage_name) { :test } let(:project) { create(:project) } - let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: project.creator, project: project }) } + let(:stage_options) { { from: 2.days.ago, current_user: project.creator, project: project } } + let(:stage) { described_class.new(options: stage_options) } it_behaves_like 'base stage' @@ -40,5 +41,7 @@ describe Gitlab::CycleAnalytics::TestStage do it 'counts median from issues with metrics' do expect(stage.project_median).to eq(ISSUES_MEDIAN) end + + include_examples 'calculate #median with date range' end end |