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

55 lines
1.2 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe Gitlab::Ci::Config::Entry::Validatable do
let(:entry) { Class.new }
2016-08-24 12:49:21 +05:30
before do
2017-08-17 22:00:37 +05:30
entry.include(described_class)
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)
.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
let(:entry_instance) { entry.new }
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