BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
fea77624
Commit
fea77624
authored
Jul 07, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delegate methods to default CI entry if undefined
parent
b0ae0d73
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
20 deletions
+79
-20
entry.rb
lib/gitlab/ci/config/node/entry.rb
+5
-0
undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+26
-3
factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+4
-2
undefined_spec.rb
spec/lib/gitlab/ci/config/node/undefined_spec.rb
+44
-15
No files found.
lib/gitlab/ci/config/node/entry.rb
View file @
fea77624
...
@@ -14,6 +14,7 @@ module Gitlab
...
@@ -14,6 +14,7 @@ module Gitlab
def
initialize
(
config
)
def
initialize
(
config
)
@config
=
config
@config
=
config
@nodes
=
{}
@nodes
=
{}
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
@validator
.
validate
end
end
...
@@ -71,6 +72,10 @@ module Gitlab
...
@@ -71,6 +72,10 @@ module Gitlab
true
true
end
end
def
attributes
{
key:
@key
,
parent:
@parent
,
description:
@description
}
end
def
self
.
default
def
self
.
default
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
View file @
fea77624
...
@@ -5,8 +5,9 @@ module Gitlab
...
@@ -5,8 +5,9 @@ module Gitlab
##
##
# This class represents an undefined entry node.
# This class represents an undefined entry node.
#
#
# It takes original entry class as configuration and returns default
# It takes original entry class as configuration and creates an object
# value of original entry as self value.
# if original entry has a default value. If there is default value
# some methods are delegated to it.
#
#
#
#
class
Undefined
<
Entry
class
Undefined
<
Entry
...
@@ -16,13 +17,35 @@ module Gitlab
...
@@ -16,13 +17,35 @@ module Gitlab
validates
:config
,
type:
Class
validates
:config
,
type:
Class
end
end
def
initialize
(
node
)
super
unless
node
.
default
.
nil?
@default
=
fabricate_default
(
node
)
end
end
def
value
def
value
@config
.
default
@default
.
value
if
@default
end
def
valid?
@default
?
@default
.
valid?
:
true
end
def
errors
@default
?
@default
.
errors
:
[]
end
end
def
defined?
def
defined?
false
false
end
end
private
def
fabricate_default
(
node
)
Node
::
Factory
.
fabricate
(
node
,
node
.
default
,
attributes
)
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
View file @
fea77624
...
@@ -9,11 +9,13 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -9,11 +9,13 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'fabricates entry with attributes set'
do
it
'fabricates entry with attributes set'
do
fabricated
=
described_class
fabricated
=
described_class
.
fabricate
(
entry_class
,
[
'ls'
],
.
fabricate
(
entry_class
,
[
'ls'
],
parent:
factory
,
key: :test
)
parent:
true
,
key: :test
)
expect
(
fabricated
.
parent
).
to
be
factory
expect
(
fabricated
.
parent
).
to
be
true
expect
(
fabricated
.
key
).
to
eq
:test
expect
(
fabricated
.
key
).
to
eq
:test
expect
(
fabricated
.
value
).
to
eq
[
'ls'
]
expect
(
fabricated
.
value
).
to
eq
[
'ls'
]
expect
(
fabricated
.
attributes
)
.
to
eq
(
parent:
true
,
key: :test
,
description:
nil
)
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/undefined_spec.rb
View file @
fea77624
...
@@ -2,33 +2,62 @@ require 'spec_helper'
...
@@ -2,33 +2,62 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
do
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:entry
)
{
Class
.
new
}
let
(
:entry
)
{
spy
(
'Entry'
)
}
describe
'#leaf?'
do
context
'when entry does not have a default value'
do
it
'is leaf node'
do
before
{
allow
(
entry
).
to
receive
(
:default
).
and_return
(
nil
)
}
expect
(
undefined
).
to
be_leaf
describe
'#leaf?'
do
it
'is leaf node'
do
expect
(
undefined
).
to
be_leaf
end
end
end
end
describe
'#valid?'
do
describe
'#valid?'
do
it
'is always valid'
do
it
'is always valid'
do
expect
(
undefined
).
to
be_valid
expect
(
undefined
).
to
be_valid
end
end
end
end
describe
'#errors'
do
describe
'#errors'
do
it
'is does not contain errors'
do
it
'is does not contain errors'
do
expect
(
undefined
.
errors
).
to
be_empty
expect
(
undefined
.
errors
).
to
be_empty
end
end
describe
'#value'
do
it
'returns nil'
do
expect
(
undefined
.
value
).
to
eq
nil
end
end
end
end
end
describe
'#
value'
do
context
'when entry has a default
value'
do
before
do
before
do
allow
(
entry
).
to
receive
(
:default
).
and_return
(
'some value'
)
allow
(
entry
).
to
receive
(
:default
).
and_return
(
'some value'
)
allow
(
entry
).
to
receive
(
:value
).
and_return
(
'some value'
)
end
end
it
'returns default value for entry'
do
describe
'#value'
do
expect
(
undefined
.
value
).
to
eq
'some value'
it
'returns default value for entry'
do
expect
(
undefined
.
value
).
to
eq
'some value'
end
end
describe
'#errors'
do
it
'delegates errors to default entry'
do
expect
(
entry
).
to
receive
(
:errors
)
undefined
.
errors
end
end
describe
'#valid?'
do
it
'delegates valid? to default entry'
do
expect
(
entry
).
to
receive
(
:valid?
)
undefined
.
valid?
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment