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 | |
parent | eadb77d89f5f7d445bfd326f18873168f4719f12 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/badge/pipeline/template_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/status/preparing_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/code_stage_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/issue_stage_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/plan_stage_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb | 84 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/staging_stage_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/test_stage_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/favicon_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/storage_settings_spec.rb | 32 |
11 files changed, 151 insertions, 17 deletions
diff --git a/spec/lib/gitlab/badge/pipeline/template_spec.rb b/spec/lib/gitlab/badge/pipeline/template_spec.rb index c0aaa3d73e1..da95c7219a4 100644 --- a/spec/lib/gitlab/badge/pipeline/template_spec.rb +++ b/spec/lib/gitlab/badge/pipeline/template_spec.rb @@ -67,7 +67,7 @@ describe Gitlab::Badge::Pipeline::Template do end it 'has expected color' do - expect(template.value_color).to eq '#dfb317' + expect(template.value_color).to eq '#a7a7a7' end end diff --git a/spec/lib/gitlab/ci/status/preparing_spec.rb b/spec/lib/gitlab/ci/status/preparing_spec.rb index 7211c0e506d..33f6bab8d65 100644 --- a/spec/lib/gitlab/ci/status/preparing_spec.rb +++ b/spec/lib/gitlab/ci/status/preparing_spec.rb @@ -16,11 +16,11 @@ describe Gitlab::Ci::Status::Preparing do end describe '#icon' do - it { expect(subject.icon).to eq 'status_created' } + it { expect(subject.icon).to eq 'status_preparing' } end describe '#favicon' do - it { expect(subject.favicon).to eq 'favicon_status_created' } + it { expect(subject.favicon).to eq 'favicon_status_preparing' } end describe '#group' do 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 diff --git a/spec/lib/gitlab/favicon_spec.rb b/spec/lib/gitlab/favicon_spec.rb index d221f39c2ed..617c0f88a89 100644 --- a/spec/lib/gitlab/favicon_spec.rb +++ b/spec/lib/gitlab/favicon_spec.rb @@ -57,6 +57,7 @@ RSpec.describe Gitlab::Favicon, :request_store do favicon_status_manual favicon_status_not_found favicon_status_pending + favicon_status_preparing favicon_status_running favicon_status_scheduled favicon_status_skipped diff --git a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb index f2f53982b09..2f83e5a5221 100644 --- a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb +++ b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb @@ -27,6 +27,38 @@ describe Gitlab::GitalyClient::StorageSettings do end end + describe '.gitaly_address' do + context 'when the storage settings have no gitaly address but one is requested' do + it 'raises an error' do + expect do + described_class.new("path" => Rails.root).gitaly_address + end.to raise_error("key not found: \"gitaly_address\"") + end + end + + context 'when the storage settings have a gitaly address and one is requested' do + it 'returns the setting value' do + expect(described_class.new("path" => Rails.root, "gitaly_address" => "test").gitaly_address).to eq("test") + end + end + + context 'when the storage settings have a gitaly address keyed symbolically' do + it 'raises no error' do + expect do + described_class.new("path" => Rails.root, :gitaly_address => "test").gitaly_address + end.not_to raise_error + end + end + + context 'when the storage settings have a gitaly address keyed with a string' do + it 'raises no error' do + expect do + described_class.new("path" => Rails.root, "gitaly_address" => "test").gitaly_address + end.not_to raise_error + end + end + end + describe '.disk_access_denied?' do context 'when Rugged is enabled', :enable_rugged do it 'returns false' do |