BigW Consortium Gitlab

environments.rb 1.58 KB
Newer Older
1 2 3 4 5
FactoryGirl.define do
  factory :environment, class: Environment do
    sequence(:name) { |n| "environment#{n}" }

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

    trait :with_review_app do |environment|
      project

11 12 13 14
      transient do
        ref 'master'
      end

15 16 17 18 19
      # 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.
      #
20
      after(:create) do |environment, evaluator|
21 22
        pipeline = create(:ci_pipeline, project: environment.project)

23 24 25
        deployable = create(:ci_build, name: "#{environment.name}:deploy",
                                       pipeline: pipeline)

26 27 28
        deployment = create(:deployment,
                            environment: environment,
                            project: environment.project,
29
                            deployable: deployable,
30 31
                            ref: evaluator.ref,
                            sha: environment.project.commit(evaluator.ref).id)
32 33

        teardown_build = create(:ci_build, :manual,
34
                                name: "#{environment.name}:teardown",
35
                                pipeline: pipeline)
36 37 38 39 40

        deployment.update_column(:on_stop, teardown_build.name)
        environment.update_attribute(:deployments, [deployment])
      end
    end
Filipa Lacerda committed
41 42 43 44 45

    trait :non_playable do
      status 'created'
      self.when 'manual'
    end
46 47
  end
end