# frozen_string_literal: true
FactoryBot.define do
# TODO: we can remove this factory in favour of :ci_pipeline
factory :ci_empty_pipeline, class: Ci::Pipeline do
source { :push }
ref { 'master' }
sha { '97de212e80737a608d939f648d959671fb0a0142' }
status { 'pending' }
add_attribute(:protected) { false }
project
# Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references
transient { head_pipeline_of { nil } }
after(:create) do |pipeline, evaluator|
merge_request = evaluator.head_pipeline_of
merge_request&.update(head_pipeline: pipeline)
end
factory :ci_pipeline do
trait :invalid do
yaml_errors { 'invalid YAML' }
failure_reason { :config_error }
trait :created do
status { :created }
trait :preparing do
status { :preparing }
trait :blocked do
status { :manual }
trait :scheduled do
status { :scheduled }
trait :success do
status { :success }
trait :running do
status { :running }
trait :failed do
status { :failed }
trait :protected do
add_attribute(:protected) { true }
trait :with_test_reports do
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :test_reports, pipeline: pipeline, project: pipeline.project)
trait :with_exposed_artifacts do
pipeline.builds << build(:ci_build, :artifacts,
pipeline: pipeline,
project: pipeline.project,
options: { artifacts: { expose_as: 'the artifact', paths: ['ci_artifacts.txt'] } })
trait :with_job do
pipeline.builds << build(:ci_build, pipeline: pipeline, project: pipeline.project)
trait :auto_devops_source do
config_source { Ci::Pipeline.config_sources[:auto_devops_source] }
trait :repository_source do
config_source { Ci::Pipeline.config_sources[:repository_source] }