a5a444906d
If `project_auto_devops.enabled` is nil for a project, when setting any auto devops values via the API, we try to create a new row in the DB, instead of re-using the existing one. This leads to the project_id being set to nil, and the database `NOT NULL` constraint leading to a 500 response. This commit resolves the issue by correctly detecting the presence of a ProjectAutoDevops row and re-using it. Persistence is also moved away from explicit `update!` calls and into relying on `autosave: true` on the model.
59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
# 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
|