Add CI config entry location info to error message
This CI config entry location in configuration Hash.
This commit is contained in:
parent
7c511c2f55
commit
92312786f1
|
@ -8,9 +8,8 @@ module Gitlab
|
|||
class Entry
|
||||
class InvalidError < StandardError; end
|
||||
|
||||
attr_writer :key
|
||||
attr_reader :config
|
||||
attr_accessor :parent, :description
|
||||
attr_accessor :key, :parent, :description
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
|
@ -35,10 +34,6 @@ module Gitlab
|
|||
self.class.nodes.none?
|
||||
end
|
||||
|
||||
def key
|
||||
@key || self.class.name.demodulize.underscore
|
||||
end
|
||||
|
||||
def valid?
|
||||
errors.none?
|
||||
end
|
||||
|
|
|
@ -8,17 +8,24 @@ module Gitlab
|
|||
|
||||
def initialize(node)
|
||||
super(node)
|
||||
@node = node
|
||||
end
|
||||
|
||||
def messages
|
||||
errors.full_messages.map do |error|
|
||||
"#{key} #{error}".humanize
|
||||
"#{location} #{error}".humanize
|
||||
end
|
||||
end
|
||||
|
||||
def self.name
|
||||
'Validator'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def location
|
||||
key || @node.class.name.demodulize.underscore
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,12 +13,6 @@ describe Gitlab::Ci::Config::Node::Global do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#key' do
|
||||
it 'returns underscored class name' do
|
||||
expect(global.key).to eq 'global'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when hash is valid' do
|
||||
context 'when all entries defined' do
|
||||
let(:hash) do
|
||||
|
|
|
@ -5,6 +5,10 @@ describe Gitlab::Ci::Config::Node::Validator do
|
|||
let(:validator_instance) { validator.new(node) }
|
||||
let(:node) { spy('node') }
|
||||
|
||||
before do
|
||||
allow(node).to receive(:key).and_return('node')
|
||||
end
|
||||
|
||||
describe 'delegated validator' do
|
||||
before do
|
||||
validator.class_eval do
|
||||
|
@ -42,7 +46,8 @@ describe Gitlab::Ci::Config::Node::Validator do
|
|||
it 'returns errors' do
|
||||
validator_instance.validate
|
||||
|
||||
expect(validator_instance.messages).not_to be_empty
|
||||
expect(validator_instance.messages)
|
||||
.to include "Node test attribute can't be blank"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue