Add validation of URL and validation of name
This commit is contained in:
parent
ba5bd3d1d6
commit
08272ec151
2 changed files with 35 additions and 0 deletions
|
@ -11,6 +11,11 @@ module Gitlab
|
|||
validations do
|
||||
validates :name, presence: true
|
||||
|
||||
validates :url,
|
||||
length: { maximum: 255 },
|
||||
allow_nil: true,
|
||||
addressable_url: true
|
||||
|
||||
validate do
|
||||
unless hash? || string?
|
||||
errors.add(:config, 'should be a hash or a string')
|
||||
|
|
|
@ -87,6 +87,19 @@ describe Gitlab::Ci::Config::Node::Environment do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when variables are used for environment' do
|
||||
let(:config) do
|
||||
{ name: 'review/$CI_BUILD_REF_NAME',
|
||||
url: 'https://$CI_BUILD_REF_NAME.review.gitlab.com' }
|
||||
end
|
||||
|
||||
describe '#valid?' do
|
||||
it 'is valid' do
|
||||
expect(entry).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when configuration is invalid' do
|
||||
context 'when configuration is an array' do
|
||||
let(:config) { ['env'] }
|
||||
|
@ -121,5 +134,22 @@ describe Gitlab::Ci::Config::Node::Environment do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when invalid URL is used' do
|
||||
let(:config) { { name: 'test', url: 'invalid-example.gitlab.com' } }
|
||||
|
||||
describe '#valid?' do
|
||||
it 'is not valid' do
|
||||
expect(entry).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe '#errors?' do
|
||||
it 'contains error about invalid URL' do
|
||||
expect(entry.errors)
|
||||
.to include "environment url must be a valid url"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue