diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 09:09:31 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 09:09:31 +0000 |
commit | 6763d2787670bc03a36a8eb601703e88fc70dece (patch) | |
tree | edc653ffd3052e3f9898c4fa8a07621d51574767 /spec/models | |
parent | ed9165c2abda1dca048a8d3cb8030d906c0bbb0c (diff) | |
download | gitlab-ce-6763d2787670bc03a36a8eb601703e88fc70dece.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/daily_report_result_spec.rb | 62 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 4 |
3 files changed, 86 insertions, 3 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 849494e7cd4..c87272b2309 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4244,12 +4244,12 @@ describe User, :do_not_mock_admin_mode do let!(:non_internal) { [user] } let!(:internal) { [ghost, alert_bot] } - it 'returns non internal users' do + it 'returns internal users' do expect(described_class.internal).to eq(internal) expect(internal.all?(&:internal?)).to eq(true) end - it 'returns internal users' do + it 'returns non internal users' do expect(described_class.non_internal).to eq(non_internal) expect(non_internal.all?(&:internal?)).to eq(false) end |