BigW Consortium Gitlab

Commit 04ece666 by Grzegorz Bizon

Add ci config class that represents a key value

parent 823970b5
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a key.
#
class Key < Entry
include Validatable
validations do
validates :config, key: true
end
end
end
end
end
end
......@@ -13,6 +13,16 @@ module Gitlab
end
end
class KeyValidator < ActiveModel::EachValidator
include LegacyValidationHelpers
def validate_each(record, attribute, value)
unless validate_string(value)
record.errors.add(attribute, 'should be a string or symbol')
end
end
end
class TypeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
type = options[:with]
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Key do
let(:entry) { described_class.new(config) }
describe 'validations' do
context 'when entry config value is correct' do
let(:config) { 'test' }
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq 'test'
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
let(:config) { [ 'incorrect' ] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'Key config should be a string or symbol'
end
end
end
end
end
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