Commit fad63dfb authored by Maxime Orefice's avatar Maxime Orefice Committed by Douglas Barbosa Alexandre

Expose locked artifacts for pipeline downloadable_artifact

parent ded4a188
......@@ -70,7 +70,9 @@ module Ci
has_many :deployments, through: :builds
has_many :environments, -> { distinct }, through: :deployments
has_many :latest_builds, -> { latest.with_project_and_metadata }, foreign_key: :commit_id, inverse_of: :pipeline, class_name: 'Ci::Build'
has_many :downloadable_artifacts, -> { not_expired.downloadable.with_job }, through: :latest_builds, source: :job_artifacts
has_many :downloadable_artifacts, -> do
not_expired.or(where_exists(::Ci::Pipeline.artifacts_locked.where('ci_pipelines.id = ci_builds.commit_id'))).downloadable.with_job
end, through: :latest_builds, source: :job_artifacts
has_many :messages, class_name: 'Ci::PipelineMessage', inverse_of: :pipeline
......
---
title: Fix downloadable artifacts for pipeline
merge_request: 60836
author:
type: fixed
......@@ -68,14 +68,23 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
describe '#downloadable_artifacts' do
let(:build) { create(:ci_build, pipeline: pipeline) }
let_it_be(:build) { create(:ci_build, pipeline: pipeline) }
let_it_be(:downloadable_artifact) { create(:ci_job_artifact, :codequality, job: build) }
let_it_be(:expired_artifact) { create(:ci_job_artifact, :junit, :expired, job: build) }
let_it_be(:undownloadable_artifact) { create(:ci_job_artifact, :trace, job: build) }
it 'returns downloadable artifacts that have not expired' do
downloadable_artifact = create(:ci_job_artifact, :codequality, job: build)
_expired_artifact = create(:ci_job_artifact, :junit, :expired, job: build)
_undownloadable_artifact = create(:ci_job_artifact, :trace, job: build)
context 'when artifacts are locked' do
it 'returns downloadable artifacts including locked artifacts' do
expect(pipeline.downloadable_artifacts).to contain_exactly(downloadable_artifact, expired_artifact)
end
end
expect(pipeline.downloadable_artifacts).to contain_exactly(downloadable_artifact)
context 'when artifacts are unlocked' do
it 'returns only downloadable artifacts not expired' do
expired_artifact.job.pipeline.unlocked!
expect(pipeline.reload.downloadable_artifacts).to contain_exactly(downloadable_artifact)
end
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