Commit e017e1b6 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add ci config class that represents a boolean value

parent 04ece666
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
...@@ -13,6 +13,16 @@ module Gitlab ...@@ -13,6 +13,16 @@ module Gitlab
end end
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 class KeyValidator < ActiveModel::EachValidator
include LegacyValidationHelpers include LegacyValidationHelpers
......
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
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