pipelines.rb 1.6 KB
Newer Older
D
Douwe Maan 已提交
1
FactoryGirl.define do
2
  factory :ci_empty_pipeline, class: Ci::Pipeline do
3
    source :push
4
    ref 'master'
D
Douwe Maan 已提交
5
    sha '97de212e80737a608d939f648d959671fb0a0142'
6
    status 'pending'
D
Douwe Maan 已提交
7

K
Kamil Trzcinski 已提交
8
    project factory: :empty_project
K
WIP  
Kamil Trzcinski 已提交
9

10
    factory :ci_pipeline_without_jobs do
11 12
      after(:build) do |pipeline|
        allow(pipeline).to receive(:ci_yaml_file) { YAML.dump({}) }
D
Douwe Maan 已提交
13 14 15
      end
    end

16
    factory :ci_pipeline_with_one_job do
17 18 19 20
      after(:build) do |pipeline|
        allow(pipeline).to receive(:ci_yaml_file) do
          YAML.dump({ rspec: { script: "ls" } })
        end
D
Douwe Maan 已提交
21 22 23
      end
    end

24 25 26 27 28 29 30 31 32
    # Persist merge request head_pipeline_id
    # on pipeline factories to avoid circular references
    transient { head_pipeline_of nil }

    after(:create) do |pipeline, evaluator|
      merge_request = evaluator.head_pipeline_of
      merge_request&.update(head_pipeline: pipeline)
    end

33
    factory :ci_pipeline do
34
      transient { config nil }
35 36

      after(:build) do |pipeline, evaluator|
37 38 39 40 41 42 43
        allow(pipeline).to receive(:ci_yaml_file) do
          if evaluator.config
            YAML.dump(evaluator.config)
          else
            File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
          end
        end
44 45 46 47

        # Populates pipeline with errors
        #
        pipeline.config_processor if evaluator.config
48
      end
49 50 51 52

      trait :invalid do
        config(rspec: nil)
      end
53 54 55 56 57 58 59 60

      trait :blocked do
        status :manual
      end

      trait :success do
        status :success
      end
S
Sean McGivern 已提交
61 62 63 64

      trait :failed do
        status :failed
      end
65
    end
D
Douwe Maan 已提交
66 67
  end
end