diff options
Diffstat (limited to 'spec/finders/ci')
4 files changed, 89 insertions, 35 deletions
diff --git a/spec/finders/ci/daily_build_group_report_results_finder_spec.rb b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb index c0434b5f371..28a732fda82 100644 --- a/spec/finders/ci/daily_build_group_report_results_finder_spec.rb +++ b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb @@ -4,57 +4,77 @@ require 'spec_helper' RSpec.describe Ci::DailyBuildGroupReportResultsFinder do describe '#execute' do - let(:project) { create(:project, :private) } - let(:ref_path) { 'refs/heads/master' } + let_it_be(:project) { create(:project, :private) } + let_it_be(:current_user) { project.owner } + let_it_be(:ref_path) { 'refs/heads/master' } let(:limit) { nil } + let_it_be(:default_branch) { false } - let!(:rspec_coverage_1) { create_daily_coverage('rspec', 79.0, '2020-03-09') } - let!(:karma_coverage_1) { create_daily_coverage('karma', 89.0, '2020-03-09') } - let!(:rspec_coverage_2) { create_daily_coverage('rspec', 95.0, '2020-03-10') } - let!(:karma_coverage_2) { create_daily_coverage('karma', 92.0, '2020-03-10') } - let!(:rspec_coverage_3) { create_daily_coverage('rspec', 97.0, '2020-03-11') } - let!(:karma_coverage_3) { create_daily_coverage('karma', 99.0, '2020-03-11') } + let_it_be(:rspec_coverage_1) { create_daily_coverage('rspec', 79.0, '2020-03-09') } + let_it_be(:karma_coverage_1) { create_daily_coverage('karma', 89.0, '2020-03-09') } + let_it_be(:rspec_coverage_2) { create_daily_coverage('rspec', 95.0, '2020-03-10') } + let_it_be(:karma_coverage_2) { create_daily_coverage('karma', 92.0, '2020-03-10') } + let_it_be(:rspec_coverage_3) { create_daily_coverage('rspec', 97.0, '2020-03-11') } + let_it_be(:karma_coverage_3) { create_daily_coverage('karma', 99.0, '2020-03-11') } - subject do - described_class.new( + let(:attributes) do + { current_user: current_user, project: project, ref_path: ref_path, start_date: '2020-03-09', end_date: '2020-03-10', limit: limit - ).execute + } end - context 'when current user is allowed to read build report results' do - let(:current_user) { project.owner } + subject(:coverages) do + described_class.new(**attributes).execute + end + + context 'when ref_path is present' do + context 'when current user is allowed to read build report results' do + it 'returns all matching results within the given date range' do + expect(coverages).to match_array([ + karma_coverage_2, + rspec_coverage_2, + karma_coverage_1, + rspec_coverage_1 + ]) + end + + context 'and limit is specified' do + let(:limit) { 2 } - it 'returns all matching results within the given date range' do - expect(subject).to match_array([ - karma_coverage_2, - rspec_coverage_2, - karma_coverage_1, - rspec_coverage_1 - ]) + it 'returns limited number of matching results within the given date range' do + expect(coverages).to match_array([ + karma_coverage_2, + rspec_coverage_2 + ]) + end + end end - context 'and limit is specified' do - let(:limit) { 2 } + context 'when current user is not allowed to read build report results' do + let(:current_user) { create(:user) } - it 'returns limited number of matching results within the given date range' do - expect(subject).to match_array([ - karma_coverage_2, - rspec_coverage_2 - ]) + it 'returns an empty result' do + expect(coverages).to be_empty end end end - context 'when current user is not allowed to read build report results' do - let(:current_user) { create(:user) } + context 'when ref_path is not present' do + let(:ref_path) { nil } - it 'returns an empty result' do - expect(subject).to be_empty + context 'when coverages exist for the default branch' do + let(:default_branch) { true } + + it 'returns coverage for the default branch' do + rspec_coverage_4 = create_daily_coverage('rspec', 66.0, '2020-03-10') + + expect(coverages).to contain_exactly(rspec_coverage_4) + end end end end @@ -65,10 +85,11 @@ RSpec.describe Ci::DailyBuildGroupReportResultsFinder do create( :ci_daily_build_group_report_result, project: project, - ref_path: ref_path, + ref_path: ref_path || 'feature-branch', group_name: group_name, data: { 'coverage' => coverage }, - date: date + date: date, + default_branch: default_branch ) end end diff --git a/spec/finders/ci/pipeline_schedules_finder_spec.rb b/spec/finders/ci/pipeline_schedules_finder_spec.rb index 57842bbecd7..535c684289e 100644 --- a/spec/finders/ci/pipeline_schedules_finder_spec.rb +++ b/spec/finders/ci/pipeline_schedules_finder_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Ci::PipelineSchedulesFinder do let!(:active_schedule) { create(:ci_pipeline_schedule, project: project) } let!(:inactive_schedule) { create(:ci_pipeline_schedule, :inactive, project: project) } - subject { described_class.new(project).execute(params) } + subject { described_class.new(project).execute(**params) } describe "#execute" do context 'when the scope is nil' do diff --git a/spec/finders/ci/pipelines_finder_spec.rb b/spec/finders/ci/pipelines_finder_spec.rb index a2a714689ba..16561aa65b6 100644 --- a/spec/finders/ci/pipelines_finder_spec.rb +++ b/spec/finders/ci/pipelines_finder_spec.rb @@ -72,7 +72,7 @@ RSpec.describe Ci::PipelinesFinder do create(:ci_sources_pipeline, pipeline: child_pipeline, source_pipeline: parent_pipeline) end - it 'filters out child pipelines and show only the parents' do + it 'filters out child pipelines and shows only the parents by default' do is_expected.to eq([parent_pipeline]) end end @@ -195,6 +195,21 @@ RSpec.describe Ci::PipelinesFinder do end end + context 'when iids filter is specified' do + let(:params) { { iids: [pipeline1.iid, pipeline3.iid] } } + let!(:pipeline1) { create(:ci_pipeline, project: project) } + let!(:pipeline2) { create(:ci_pipeline, project: project) } + let!(:pipeline3) { create(:ci_pipeline, project: project, source: :parent_pipeline) } + + it 'returns matches pipelines' do + is_expected.to match_array([pipeline1, pipeline3]) + end + + it 'does not fitler out child pipelines' do + is_expected.to include(pipeline3) + end + end + context 'when sha is specified' do let!(:pipeline) { create(:ci_pipeline, project: project, sha: '97de212e80737a608d939f648d959671fb0a0142') } diff --git a/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb b/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb index 65f6dc0ba74..64b3c46e122 100644 --- a/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb +++ b/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb @@ -225,6 +225,24 @@ RSpec.describe Ci::PipelinesForMergeRequestFinder do branch_pipeline_2, branch_pipeline]) end + + context 'when ci_pipelines_for_merge_request_finder_new_cte feature flag is disabled' do + before do + stub_feature_flags(ci_pipelines_for_merge_request_finder_new_cte: false) + end + + it 'returns only related merge request pipelines' do + expect(subject.all) + .to eq([detached_merge_request_pipeline, + branch_pipeline_2, + branch_pipeline]) + + expect(described_class.new(merge_request_2, nil).all) + .to eq([detached_merge_request_pipeline_2, + branch_pipeline_2, + branch_pipeline]) + end + end end context 'when detached merge request pipeline is run on head ref of the merge request' do |