debian-mirror-gitlab/spec/factories/environments.rb

57 lines
1.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2020-03-13 15:44:24 +05:30
factory :environment, class: 'Environment' do
sequence(:name) { |n| "environment#{n}" }
2017-09-10 17:25:29 +05:30
association :project, :repository
2016-09-13 17:45:13 +05:30
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
2017-08-17 22:00:37 +05:30
trait :with_review_app do |environment|
transient do
2019-12-21 20:55:43 +05:30
ref { 'master' }
2017-08-17 22:00:37 +05:30
end
# At this point `review app` is an ephemeral concept related to
# deployments being deployed for given environment. There is no
# first-class `review app` available so we need to create set of
# interconnected objects to simulate a review app.
#
after(:create) do |environment, evaluator|
pipeline = create(:ci_pipeline, project: environment.project)
deployable = create(:ci_build, name: "#{environment.name}:deploy",
pipeline: pipeline)
deployment = create(:deployment,
2018-12-13 13:39:08 +05:30
:success,
2017-08-17 22:00:37 +05:30
environment: environment,
project: environment.project,
deployable: deployable,
ref: evaluator.ref,
sha: environment.project.commit(evaluator.ref).id)
teardown_build = create(:ci_build, :manual,
name: "#{environment.name}:teardown",
pipeline: pipeline)
deployment.update_column(:on_stop, teardown_build.name)
environment.update_attribute(:deployments, [deployment])
end
end
trait :non_playable do
2019-12-21 20:55:43 +05:30
status { 'created' }
self.when { 'manual' }
2017-08-17 22:00:37 +05:30
end
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
trait :auto_stoppable do
2020-01-01 13:55:28 +05:30
auto_stop_at { 1.day.ago }
end
trait :will_auto_stop do
auto_stop_at { 1.day.from_now }
end
end
end