gitlab-org--gitlab-foss/spec/factories/ci/pipelines.rb

71 lines
1.7 KiB
Ruby
Raw Normal View History

FactoryBot.define do
factory :ci_empty_pipeline, class: Ci::Pipeline do
2017-05-24 09:13:51 -04:00
source :push
ref 'master'
2015-08-25 21:42:46 -04:00
sha '97de212e80737a608d939f648d959671fb0a0142'
status 'pending'
protected false
2015-08-25 21:42:46 -04:00
project
2015-09-28 07:14:34 -04:00
factory :ci_pipeline_without_jobs do
after(:build) do |pipeline|
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({}))
2015-08-25 21:42:46 -04:00
end
end
factory :ci_pipeline_with_one_job do
after(:build) do |pipeline|
allow(pipeline).to receive(:ci_yaml_file) do
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({ rspec: { script: "ls" } }))
end
2015-08-25 21:42:46 -04:00
end
end
# 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
transient { config nil }
after(:build) do |pipeline, evaluator|
if evaluator.config
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump(evaluator.config))
# Populates pipeline with errors
pipeline.config_processor if evaluator.config
else
pipeline.instance_variable_set(:@ci_yaml_file, File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
end
end
trait :invalid do
config(rspec: nil)
failure_reason :config_error
end
trait :blocked do
status :manual
end
trait :success do
status :success
end
trait :failed do
status :failed
end
trait :protected do
protected true
end
end
2015-08-25 21:42:46 -04:00
end
end