2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2016-06-14 07:51:12 -04:00
|
|
|
factory :environment, class: Environment do
|
|
|
|
sequence(:name) { |n| "environment#{n}" }
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
association :project, :repository
|
2016-07-26 03:35:47 -04:00
|
|
|
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
|
2016-11-09 03:42:09 -05:00
|
|
|
|
|
|
|
trait :with_review_app do |environment|
|
2016-11-14 08:10:54 -05:00
|
|
|
transient do
|
|
|
|
ref 'master'
|
|
|
|
end
|
|
|
|
|
2016-11-09 03:42:09 -05:00
|
|
|
# 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.
|
|
|
|
#
|
2016-11-14 08:10:54 -05:00
|
|
|
after(:create) do |environment, evaluator|
|
2017-04-06 08:28:40 -04:00
|
|
|
pipeline = create(:ci_pipeline, project: environment.project)
|
|
|
|
|
2017-04-06 09:19:52 -04:00
|
|
|
deployable = create(:ci_build, name: "#{environment.name}:deploy",
|
|
|
|
pipeline: pipeline)
|
|
|
|
|
2016-11-09 03:42:09 -05:00
|
|
|
deployment = create(:deployment,
|
|
|
|
environment: environment,
|
|
|
|
project: environment.project,
|
2017-04-06 09:19:52 -04:00
|
|
|
deployable: deployable,
|
2016-11-14 08:10:54 -05:00
|
|
|
ref: evaluator.ref,
|
|
|
|
sha: environment.project.commit(evaluator.ref).id)
|
2016-11-09 03:42:09 -05:00
|
|
|
|
|
|
|
teardown_build = create(:ci_build, :manual,
|
2017-04-06 09:19:52 -04:00
|
|
|
name: "#{environment.name}:teardown",
|
2017-04-06 08:28:40 -04:00
|
|
|
pipeline: pipeline)
|
2016-11-09 03:42:09 -05:00
|
|
|
|
|
|
|
deployment.update_column(:on_stop, teardown_build.name)
|
|
|
|
environment.update_attribute(:deployments, [deployment])
|
|
|
|
end
|
|
|
|
end
|
2017-04-04 04:14:46 -04:00
|
|
|
|
|
|
|
trait :non_playable do
|
|
|
|
status 'created'
|
|
|
|
self.when 'manual'
|
|
|
|
end
|
2016-06-14 07:51:12 -04:00
|
|
|
end
|
|
|
|
end
|