Fix creation of job_artifact_uploader

This commit is contained in:
Kamil Trzcinski 2017-11-02 12:16:50 +01:00
parent 61864a5a5b
commit 303f165cba
4 changed files with 10 additions and 12 deletions

View File

@ -15,11 +15,11 @@ module Ci
has_one :last_deployment, -> { order('deployments.id DESC') }, as: :deployable, class_name: 'Deployment'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :ci_job_id
# TODO: what to do with dependent destroy
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :ci_job_id, dependent: :destroy
has_one :job_archive, -> () { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', foreign_key: :ci_job_id
has_one :job_metadata, -> () { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', foreign_key: :ci_job_id
# The "environment" field for builds is a String, and is the unexpanded name
def persisted_environment
@persisted_environment ||= Environment.find_by(

View File

@ -3,12 +3,6 @@ class JobArtifactUploader < ArtifactUploader
@artifact = artifact
end
# If this record exists, the associatied artifact is there. Every artifact
# persisted will have an associated file
def exists?
true
end
def size
return super unless @artifact.size

View File

@ -155,8 +155,10 @@ FactoryGirl.define do
end
trait :artifacts do
job_archive factory: :ci_job_artifact
job_metadata factory: :ci_job_metadata
after(:create) do |build|
create(:ci_job_artifact, job: build)
create(:ci_job_metadata, job: build)
end
end
trait :expired do

View File

@ -2,15 +2,17 @@ include ActionDispatch::TestProcess
FactoryGirl.define do
factory :ci_job_artifact, class: Ci::JobArtifact do
project
job factory: :ci_build
file_type :archive
after :build do |artifact|
artifact.project ||= artifact.job.project
end
after :create do |artifact|
if artifact.archive?
artifact.file = fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
'application/zip')
artifact.save
end
end