summaryrefslogtreecommitdiff
path: root/spec/models/concerns/project_api_compatibility_spec.rb
blob: f5722f88aac45a2cecedaedfe1cc722c5b380a65 (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
# frozen_string_literal: true

require 'spec_helper'

describe ProjectAPICompatibility do
  let(:project) { create(:project) }

  # git_strategy
  it "converts build_git_strategy=fetch to build_allow_git_fetch=true" do
    project.update!(build_git_strategy: 'fetch')
    expect(project.build_allow_git_fetch).to eq(true)
  end

  it "converts build_git_strategy=clone to build_allow_git_fetch=false" do
    project.update!(build_git_strategy: 'clone')
    expect(project.build_allow_git_fetch).to eq(false)
  end

  describe '#auto_devops_enabled' do
    where(
      initial: [:missing, nil, false, true],
      final: [nil, false, true]
    )

    with_them do
      before do
        project.build_auto_devops(enabled: initial) unless initial == :missing
      end

      # Implicit auto devops when enabled is nil
      let(:expected) { final.nil? ? true : final }

      it 'sets the correct value' do
        project.update!(auto_devops_enabled: final)

        expect(project.auto_devops_enabled?).to eq(expected)
      end
    end
  end

  describe '#auto_devops_deploy_strategy' do
    where(
      initial: [:missing, *ProjectAutoDevops.deploy_strategies.keys],
      final: ProjectAutoDevops.deploy_strategies.keys
    )

    with_them do
      before do
        project.build_auto_devops(deploy_strategy: initial) unless initial == :missing
      end

      it 'sets the correct value' do
        project.update!(auto_devops_deploy_strategy: final)

        expect(project.auto_devops.deploy_strategy).to eq(final)
      end
    end
  end
end