Commit 147f0428 authored by Matija Čupić's avatar Matija Čupić

Add validation for auto_devops_domain

parent 28fd7b6c
...@@ -117,6 +117,11 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -117,6 +117,11 @@ class ApplicationSetting < ActiveRecord::Base
validates :repository_storages, presence: true validates :repository_storages, presence: true
validate :check_repository_storages 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, validates :enabled_git_access_protocol,
inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true } inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true }
......
...@@ -114,6 +114,46 @@ describe ApplicationSetting do ...@@ -114,6 +114,46 @@ describe ApplicationSetting do
it { expect(setting.repository_storages).to eq(['default']) } it { expect(setting.repository_storages).to eq(['default']) }
end 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 context 'circuitbreaker settings' do
[:circuitbreaker_failure_count_threshold, [:circuitbreaker_failure_count_threshold,
:circuitbreaker_check_interval, :circuitbreaker_check_interval,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment