deployments.rb 1.11 KB
Newer Older
1
FactoryBot.define do
2 3 4
  factory :deployment, class: Deployment do
    sha '97de212e80737a608d939f648d959671fb0a0142'
    ref 'master'
Kamil Trzcinski's avatar
Kamil Trzcinski committed
5
    tag false
6
    user nil
7
    project nil
8
    deployable factory: :ci_build
9 10 11
    environment factory: :environment

    after(:build) do |deployment, evaluator|
12
      deployment.project ||= deployment.environment.project
13
      deployment.user ||= deployment.project.creator
14 15

      unless deployment.project.repository_exists?
16
        allow(deployment.project.repository).to receive(:create_ref)
17
      end
18
    end
19 20 21 22 23

    trait :review_app do
      sha { TestEnv::BRANCH_SHA['pages-deploy'] }
      ref 'pages-deploy'
    end
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

    trait :running do
      status :running
    end

    trait :success do
      status :success
      finished_at { Time.now }
    end

    trait :failed do
      status :failed
      finished_at { Time.now }
    end

    trait :canceled do
      status :canceled
      finished_at { Time.now }
    end

    # This trait hooks the state maechine's events
    trait :succeed do
      after(:create) do |deployment, evaluator|
        deployment.succeed!
      end
    end
50 51
  end
end