summaryrefslogtreecommitdiff
path: root/spec/factories/ci/bridge.rb
blob: 49ac74f6f8692b38e23d469ec66ac7a3ac4f0844 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

FactoryBot.define do
  factory :ci_bridge, class: 'Ci::Bridge', parent: :ci_processable do
    name { 'bridge' }
    created_at { '2013-10-29 09:50:00 CET' }
    status { :created }

    trait :variables do
      yaml_variables do
        [{ key: 'BRIDGE', value: 'cross', public: true }]
      end
    end

    transient do
      downstream { nil }
      upstream { nil }
    end

    after(:build) do |bridge, evaluator|
      bridge.project ||= bridge.pipeline.project

      if evaluator.downstream.present?
        bridge.options = bridge.options.to_h.merge(
          trigger: { project: evaluator.downstream.full_path }
        )
      end

      if evaluator.upstream.present?
        bridge.options = bridge.options.to_h.merge(
          bridge_needs: { pipeline: evaluator.upstream.full_path }
        )
      end
    end

    trait :retried do
      retried { true }
    end

    trait :retryable do
      success
    end

    trait :created do
      status { 'created' }
    end

    trait :started do
      started_at { '2013-10-29 09:51:28 CET' }
    end

    trait :finished do
      started
      finished_at { '2013-10-29 09:53:28 CET' }
    end

    trait :success do
      finished
      status { 'success' }
    end

    trait :failed do
      finished
      status { 'failed' }
    end

    trait :skipped do
      started
      status { 'skipped' }
    end

    trait :strategy_depend do
      options { { trigger: { strategy: 'depend' } } }
    end

    trait :manual do
      status { 'manual' }
      self.when { 'manual' }
    end

    trait :playable do
      manual
    end

    trait :allowed_to_fail do
      allow_failure { true }
    end
  end
end