2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-17 03:33:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Config::Entry::Validator do
|
2016-06-17 03:33:32 -04:00
|
|
|
let(:validator) { Class.new(described_class) }
|
|
|
|
let(:validator_instance) { validator.new(node) }
|
|
|
|
let(:node) { spy('node') }
|
|
|
|
|
2016-06-29 03:10:23 -04:00
|
|
|
before do
|
|
|
|
allow(node).to receive(:key).and_return('node')
|
2016-06-29 03:39:04 -04:00
|
|
|
allow(node).to receive(:ancestors).and_return([])
|
2016-06-29 03:10:23 -04:00
|
|
|
end
|
|
|
|
|
2016-06-27 08:12:47 -04:00
|
|
|
describe 'delegated validator' do
|
|
|
|
before do
|
|
|
|
validator.class_eval do
|
|
|
|
validates :test_attribute, presence: true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-17 03:33:32 -04:00
|
|
|
context 'when node is valid' do
|
|
|
|
before do
|
|
|
|
allow(node).to receive(:test_attribute).and_return('valid value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'validates attribute in node' do
|
|
|
|
expect(node).to receive(:test_attribute)
|
|
|
|
expect(validator_instance).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no errors' do
|
|
|
|
validator_instance.validate
|
|
|
|
|
2016-06-23 07:51:34 -04:00
|
|
|
expect(validator_instance.messages).to be_empty
|
2016-06-17 03:33:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when node is invalid' do
|
|
|
|
before do
|
|
|
|
allow(node).to receive(:test_attribute).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'validates attribute in node' do
|
|
|
|
expect(node).to receive(:test_attribute)
|
|
|
|
expect(validator_instance).to be_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns errors' do
|
|
|
|
validator_instance.validate
|
|
|
|
|
2016-06-29 03:10:23 -04:00
|
|
|
expect(validator_instance.messages)
|
2017-08-25 09:16:09 -04:00
|
|
|
.to include /test attribute can't be blank/
|
2016-06-17 03:33:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|