Commit 700078e8 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Rename unspecified and undefined CI config nodes

parent 6c704fd9
...@@ -37,8 +37,8 @@ module Gitlab ...@@ -37,8 +37,8 @@ module Gitlab
# See issue #18775. # See issue #18775.
# #
if @value.nil? if @value.nil?
Node::Undefined.new( Node::Unspecified.new(
fabricate_undefined fabricate_unspecified
) )
else else
fabricate(@node, @value) fabricate(@node, @value)
...@@ -47,13 +47,13 @@ module Gitlab ...@@ -47,13 +47,13 @@ module Gitlab
private private
def fabricate_undefined def fabricate_unspecified
## ##
# If node has a default value we fabricate concrete node # If node has a default value we fabricate concrete node
# with default value. # with default value.
# #
if @node.default.nil? if @node.default.nil?
fabricate(Node::Null) fabricate(Node::Undefined)
else else
fabricate(@node, @node.default) fabricate(@node, @node.default)
end end
......
...@@ -3,15 +3,34 @@ module Gitlab ...@@ -3,15 +3,34 @@ module Gitlab
class Config class Config
module Node module Node
## ##
# This class represents an unspecified entry node. # This class represents an undefined node.
# #
# It decorates original entry adding method that indicates it is # Implements the Null Object pattern.
# unspecified.
# #
class Undefined < SimpleDelegator class Undefined < Entry
def initialize(*)
super(nil)
end
def value
nil
end
def valid?
true
end
def errors
[]
end
def specified? def specified?
false false
end end
def relevant?
false
end
end end
end end
end end
......
...@@ -3,30 +3,15 @@ module Gitlab ...@@ -3,30 +3,15 @@ module Gitlab
class Config class Config
module Node module Node
## ##
# This class represents an undefined node. # This class represents an unspecified entry node.
# #
# Implements the Null Object pattern. # It decorates original entry adding method that indicates it is
# unspecified.
# #
class Null < Entry class Unspecified < SimpleDelegator
def value
nil
end
def valid?
true
end
def errors
[]
end
def specified? def specified?
false false
end end
def relevant?
false
end
end end
end end
end end
......
...@@ -65,7 +65,8 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -65,7 +65,8 @@ describe Gitlab::Ci::Config::Node::Factory do
.value(nil) .value(nil)
.create! .create!
expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Undefined expect(entry)
.to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified
end end
end end
......
...@@ -156,9 +156,9 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -156,9 +156,9 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.descendants.count).to eq 8 expect(global.descendants.count).to eq 8
end end
it 'contains undefined nodes' do it 'contains unspecified nodes' do
expect(global.descendants.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Undefined .to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified
end end
end end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Null do
let(:null) { described_class.new(nil) }
describe '#leaf?' do
it 'is leaf node' do
expect(null).to be_leaf
end
end
describe '#valid?' do
it 'is always valid' do
expect(null).to be_valid
end
end
describe '#errors' do
it 'is does not contain errors' do
expect(null.errors).to be_empty
end
end
describe '#value' do
it 'returns nil' do
expect(null.value).to eq nil
end
end
describe '#relevant?' do
it 'is not relevant' do
expect(null.relevant?).to eq false
end
end
describe '#specified?' do
it 'is not defined' do
expect(null.specified?).to eq false
end
end
end
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Undefined do describe Gitlab::Ci::Config::Node::Undefined do
let(:undefined) { described_class.new(entry) } let(:entry) { described_class.new }
let(:entry) { spy('Entry') }
describe '#leaf?' do
it 'is leaf node' do
expect(entry).to be_leaf
end
end
describe '#valid?' do describe '#valid?' do
it 'delegates method to entry' do it 'is always valid' do
expect(undefined.valid).to eq entry expect(entry).to be_valid
end end
end end
describe '#errors' do describe '#errors' do
it 'delegates method to entry' do it 'is does not contain errors' do
expect(undefined.errors).to eq entry expect(entry.errors).to be_empty
end end
end end
describe '#value' do describe '#value' do
it 'delegates method to entry' do it 'returns nil' do
expect(undefined.value).to eq entry expect(entry.value).to eq nil
end end
end end
describe '#specified?' do describe '#relevant?' do
it 'is always false' do it 'is not relevant' do
allow(entry).to receive(:specified?).and_return(true) expect(entry.relevant?).to eq false
end
end
expect(undefined.specified?).to be false describe '#specified?' do
it 'is not defined' do
expect(entry.specified?).to eq false
end end
end end
end end
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Unspecified do
let(:unspecified) { described_class.new(entry) }
let(:entry) { spy('Entry') }
describe '#valid?' do
it 'delegates method to entry' do
expect(unspecified.valid?).to eq entry
end
end
describe '#errors' do
it 'delegates method to entry' do
expect(unspecified.errors).to eq entry
end
end
describe '#value' do
it 'delegates method to entry' do
expect(unspecified.value).to eq entry
end
end
describe '#specified?' do
it 'is always false' do
allow(entry).to receive(:specified?).and_return(true)
expect(unspecified.specified?).to be false
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