Add validation for auto_devops_domain

This commit is contained in:
Matija Čupić 2018-01-22 19:29:15 +01:00
parent 28fd7b6c5d
commit 147f0428c0
No known key found for this signature in database
GPG Key ID: 4BAF84FFACD2E5DE
2 changed files with 45 additions and 0 deletions

View File

@ -117,6 +117,11 @@ class ApplicationSetting < ActiveRecord::Base
validates :repository_storages, presence: true
validate :check_repository_storages
validates :auto_devops_domain,
allow_blank: true,
hostname: { allow_numeric_hostname: true, require_valid_tld: true },
if: :auto_devops_enabled?
validates :enabled_git_access_protocol,
inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true }

View File

@ -114,6 +114,46 @@ describe ApplicationSetting do
it { expect(setting.repository_storages).to eq(['default']) }
end
context 'auto_devops_domain setting' do
context 'when auto_devops_enabled? is true' do
before do
setting.update(auto_devops_enabled: true)
end
context 'with a valid value' do
before do
setting.update(auto_devops_domain: 'domain.com')
end
it 'is valid' do
expect(setting).to be_valid
end
end
context 'with an invalid value' do
before do
setting.update(auto_devops_domain: 'definitelynotahostname')
end
it 'is invalid' do
expect(setting).to be_invalid
end
end
end
context 'when auto_devops_enabled? is false' do
before do
setting.update(auto_devops_enabled: false)
end
it 'can be blank' do
setting.update(auto_devops_domain: '')
expect(setting).to be_valid
end
end
end
context 'circuitbreaker settings' do
[:circuitbreaker_failure_count_threshold,
:circuitbreaker_check_interval,