pipelines.rb 1.7 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'
7
    protected false
D
Douwe Maan 已提交
8

9
    project
K
WIP  
Kamil Trzcinski 已提交
10

11
    factory :ci_pipeline_without_jobs do
12
      after(:build) do |pipeline|
13
        pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({}))
D
Douwe Maan 已提交
14 15 16
      end
    end

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

25 26 27 28 29 30 31 32 33
    # 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

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

      after(:build) do |pipeline, evaluator|
38 39
        if evaluator.config
          pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump(evaluator.config))
40

41 42 43 44 45
          # 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
46
      end
47 48 49 50

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

      trait :blocked do
        status :manual
      end

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

      trait :failed do
        status :failed
      end
63 64 65 66

      trait :protected do
        protected true
      end
67
    end
D
Douwe Maan 已提交
68 69
  end
end