Commit 1542b160 authored by Matija Čupić's avatar Matija Čupić

Extract Ci::Build#report_artifacts into method

Extracts combining the job_artifacts relation with the with_reports
scope for getting report artifacts into a method.
parent c86fa0e4
......@@ -765,6 +765,10 @@ module Ci
end
end
def report_artifacts
job_artifacts.with_reports
end
# Virtual deployment status depending on the environment status.
def deployment_status
return unless starts_environment?
......
......@@ -42,9 +42,10 @@ class BuildDetailsEntity < JobEntity
end
end
expose :reports, if: -> (*) { can?(current_user, :read_build, build) }, using: JobArtifactReportEntity do |build|
build.job_artifacts.with_reports
end
expose :report_artifacts,
as: :reports,
using: JobArtifactReportEntity,
if: -> (*) { can?(current_user, :read_build, build) }
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
......
......@@ -3490,6 +3490,18 @@ describe Ci::Build do
end
end
describe '#report_artifacts' do
subject { build.report_artifacts }
context 'when the build has reports' do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
it 'returns the artifacts with reports' do
expect(subject).to contain_exactly(report)
end
end
end
describe '#artifacts_metadata_entry' do
set(:build) { create(:ci_build, project: project) }
let(:path) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' }
......
......@@ -151,7 +151,8 @@ describe BuildDetailsEntity do
let!(:report) { create(:ci_job_artifact, :codequality, job: build) }
it 'exposes the report artifacts' do
expect(subject[:reports]).not_to be_empty
expect(subject[:reports].count).to eq(1)
expect(subject[:reports].first[:file_type]).to eq('codequality')
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment