Add ci config class that represents a boolean value

This commit is contained in:
Grzegorz Bizon
2016-06-24 09:49:54 +02:00
parent 04ece6664a
commit e017e1b629
3 changed files with 62 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a boolean value.
#
class Boolean < Entry
include Validatable
validations do
validates :config, boolean: true
end
end
end
end
end
end
+10
View File
@@ -13,6 +13,16 @@ module Gitlab
end
end
class BooleanValidator < ActiveModel::EachValidator
include LegacyValidationHelpers
def validate_each(record, attribute, value)
unless validate_boolean(value)
record.errors.add(attribute, 'should be a boolean value')
end
end
end
class KeyValidator < ActiveModel::EachValidator
include LegacyValidationHelpers
@@ -0,0 +1,34 @@
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Boolean do
let(:entry) { described_class.new(config) }
describe 'validations' do
context 'when entry config value is valid' do
let(:config) { false }
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq false
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not valid' do
let(:config) { [ 'incorrect' ] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'Boolean config should be a boolean value'
end
end
end
end
end