debian-mirror-gitlab/spec/factories/ci/processable.rb

57 lines
1.6 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
FactoryBot.define do
factory :ci_processable, class: 'Ci::Processable' do
name { 'processable' }
2023-01-13 00:05:48 +05:30
stage_idx { ci_stage.try(:position) || 0 }
2021-03-11 19:13:27 +05:30
ref { 'master' }
tag { false }
pipeline factory: :ci_pipeline
project { pipeline.project }
scheduling_type { 'stage' }
2023-04-23 21:23:45 +05:30
partition_id { pipeline.partition_id }
# This factory was updated to help with the efforts of the removal of `ci_builds.stage`:
# https://gitlab.com/gitlab-org/gitlab/-/issues/364377
# These additions can be removed once the specs that use the stage attribute have been updated
transient do
stage { 'test' }
end
after(:build) do |processable, evaluator|
processable.stage = evaluator.stage
end
before(:create) do |processable, evaluator|
next if processable.ci_stage
2023-07-09 08:55:56 +05:30
processable.ci_stage =
if ci_stage = processable.pipeline.stages.find_by(name: evaluator.stage)
ci_stage
else
create(
:ci_stage,
pipeline: processable.pipeline,
project: processable.project || evaluator.project,
name: evaluator.stage,
position: evaluator.stage_idx,
status: 'created'
)
end
2023-04-23 21:23:45 +05:30
end
2021-03-11 19:13:27 +05:30
trait :waiting_for_resource do
status { 'waiting_for_resource' }
end
trait :resource_group do
waiting_for_resource_at { 5.minutes.ago }
after(:build) do |processable, evaluator|
processable.resource_group = create(:ci_resource_group, project: processable.project)
end
end
end
end