debian-mirror-gitlab/spec/lib/gitlab/ci/config/entry/validatable_spec.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2019-01-03 12:48:30 +05:30
describe Gitlab::Ci::Config::Entry::Validatable do
2018-03-17 18:26:18 +05:30
let(:entry) do
2019-01-03 12:48:30 +05:30
Class.new(Gitlab::Ci::Config::Entry::Node) do
include Gitlab::Ci::Config::Entry::Validatable
2018-03-17 18:26:18 +05:30
end
2016-08-24 12:49:21 +05:30
end
describe '.validator' do
before do
2017-08-17 22:00:37 +05:30
entry.class_eval do
2016-08-24 12:49:21 +05:30
attr_accessor :test_attribute
validations do
validates :test_attribute, presence: true
end
end
end
it 'returns validator' do
2017-08-17 22:00:37 +05:30
expect(entry.validator.superclass)
2019-01-03 12:48:30 +05:30
.to be Gitlab::Ci::Config::Entry::Validator
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns only one validator to mitigate leaks' do
2017-08-17 22:00:37 +05:30
expect { entry.validator }.not_to change { entry.validator }
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
context 'when validating entry instance' do
2018-03-17 18:26:18 +05:30
let(:entry_instance) { entry.new('something') }
2016-08-24 12:49:21 +05:30
context 'when attribute is valid' do
before do
2017-08-17 22:00:37 +05:30
entry_instance.test_attribute = 'valid'
2016-08-24 12:49:21 +05:30
end
it 'instance of validator is valid' do
2017-08-17 22:00:37 +05:30
expect(entry.validator.new(entry_instance)).to be_valid
2016-08-24 12:49:21 +05:30
end
end
context 'when attribute is not valid' do
before do
2017-08-17 22:00:37 +05:30
entry_instance.test_attribute = nil
2016-08-24 12:49:21 +05:30
end
it 'instance of validator is invalid' do
2017-08-17 22:00:37 +05:30
expect(entry.validator.new(entry_instance)).to be_invalid
2016-08-24 12:49:21 +05:30
end
end
end
end
end