summaryrefslogtreecommitdiff
path: root/spec/factories/environments.rb
blob: 0852dda6b299eff63de0e5249226c7c374b0fec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
FactoryGirl.define do
  factory :environment, class: Environment do
    sequence(:name) { |n| "environment#{n}" }

    project factory: :empty_project
    sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }

    trait :with_review_app do |environment|
      project

      transient do
        ref 'master'
      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|
        deployment = create(:deployment,
                            environment: environment,
                            project: environment.project,
                            ref: evaluator.ref,
                            sha: environment.project.commit(evaluator.ref).id)

        teardown_build = create(:ci_build, :manual,
                                name: "#{deployment.environment.name}:teardown",
                                pipeline: deployment.deployable.pipeline)

        deployment.update_column(:on_stop, teardown_build.name)
        environment.update_attribute(:deployments, [deployment])
      end
    end
  end
end