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
      after(:build) do |pipeline|
12
        pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({}))
D
Douwe Maan 已提交
13 14 15
      end
    end

16
    factory :ci_pipeline_with_one_job do
17 18
      after(:build) do |pipeline|
        allow(pipeline).to receive(:ci_yaml_file) do
19
          pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({ rspec: { script: "ls" } }))
20
        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
        if evaluator.config
          pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump(evaluator.config))
39

40 41 42 43 44
          # Populates pipeline with errors
          pipeline.config_processor if evaluator.config
        else
          pipeline.instance_variable_set(:@ci_yaml_file, File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
        end
45
      end
46 47 48 49

      trait :invalid do
        config(rspec: nil)
      end
50 51 52 53 54 55 56 57

      trait :blocked do
        status :manual
      end

      trait :success do
        status :success
      end
S
Sean McGivern 已提交
58 59 60 61

      trait :failed do
        status :failed
      end
62
    end
D
Douwe Maan 已提交
63 64
  end
end