diff options
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/daily_report_result_spec.rb | 62 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 23 |
2 files changed, 84 insertions, 1 deletions
diff --git a/spec/models/ci/daily_report_result_spec.rb b/spec/models/ci/daily_report_result_spec.rb new file mode 100644 index 00000000000..61aa58c6692 --- /dev/null +++ b/spec/models/ci/daily_report_result_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::DailyReportResult do + describe '.upsert_reports' do + let!(:rspec_coverage) do + create( + :ci_daily_report_result, + title: 'rspec', + date: '2020-03-09', + value: 71.2 + ) + end + let!(:new_pipeline) { create(:ci_pipeline) } + + it 'creates or updates matching report results' do + described_class.upsert_reports([ + { + project_id: rspec_coverage.project_id, + ref_path: rspec_coverage.ref_path, + param_type: described_class.param_types[rspec_coverage.param_type], + last_pipeline_id: new_pipeline.id, + date: rspec_coverage.date, + title: 'rspec', + value: 81.0 + }, + { + project_id: rspec_coverage.project_id, + ref_path: rspec_coverage.ref_path, + param_type: described_class.param_types[rspec_coverage.param_type], + last_pipeline_id: new_pipeline.id, + date: rspec_coverage.date, + title: 'karma', + value: 87.0 + } + ]) + + rspec_coverage.reload + + expect(rspec_coverage).to have_attributes( + last_pipeline_id: new_pipeline.id, + value: 81.0 + ) + + expect(described_class.find_by_title('karma')).to have_attributes( + project_id: rspec_coverage.project_id, + ref_path: rspec_coverage.ref_path, + param_type: rspec_coverage.param_type, + last_pipeline_id: new_pipeline.id, + date: rspec_coverage.date, + value: 87.0 + ) + end + + context 'when given data is empty' do + it 'does nothing' do + expect { described_class.upsert_reports([]) }.not_to raise_error + end + end + end +end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index f18c77988c8..c3f2e3aebdd 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1120,7 +1120,7 @@ describe Ci::Pipeline, :mailer do let(:from_status) { status } it 'schedules pipeline success worker' do - expect(PipelineSuccessWorker).to receive(:perform_async).with(pipeline.id) + expect(Ci::DailyReportResultsWorker).to receive(:perform_in).with(10.minutes, pipeline.id) pipeline.succeed end @@ -3114,4 +3114,25 @@ describe Ci::Pipeline, :mailer do end end end + + describe '#source_ref_path' do + subject { pipeline.source_ref_path } + + context 'when pipeline is for a branch' do + it { is_expected.to eq(Gitlab::Git::BRANCH_REF_PREFIX + pipeline.source_ref.to_s) } + end + + context 'when pipeline is for a merge request' do + let(:merge_request) { create(:merge_request, source_project: project) } + let(:pipeline) { create(:ci_pipeline, project: project, head_pipeline_of: merge_request) } + + it { is_expected.to eq(Gitlab::Git::BRANCH_REF_PREFIX + pipeline.source_ref.to_s) } + end + + context 'when pipeline is for a tag' do + let(:pipeline) { create(:ci_pipeline, project: project, tag: true) } + + it { is_expected.to eq(Gitlab::Git::TAG_REF_PREFIX + pipeline.source_ref.to_s) } + end + end end |