Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
632f6ba2
Commit
632f6ba2
authored
Sep 06, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests to cover all introduced changes
parent
5941f3a7
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
221 additions
and
28 deletions
+221
-28
app/models/project.rb
app/models/project.rb
+1
-1
app/models/project_auto_devops.rb
app/models/project_auto_devops.rb
+1
-1
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+0
-1
spec/factories/project_auto_devops.rb
spec/factories/project_auto_devops.rb
+1
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+24
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+52
-21
spec/models/project_auto_devops_spec.rb
spec/models/project_auto_devops_spec.rb
+13
-4
spec/models/project_spec.rb
spec/models/project_spec.rb
+129
-0
No files found.
app/models/project.rb
View file @
632f6ba2
...
@@ -1390,7 +1390,7 @@ class Project < ActiveRecord::Base
...
@@ -1390,7 +1390,7 @@ class Project < ActiveRecord::Base
end
end
def
has_ci?
def
has_ci?
@repository
.
gitlab_ci_yml
||
@project
.
auto_devops_enabled?
repository
.
gitlab_ci_yml
||
auto_devops_enabled?
end
end
def
predefined_variables
def
predefined_variables
...
...
app/models/project_auto_devops.rb
View file @
632f6ba2
class
ProjectAutoDevops
<
ActiveRecord
::
Base
class
ProjectAutoDevops
<
ActiveRecord
::
Base
belongs_to
:project
belongs_to
:project
validates
:domain
,
presence:
true
,
hostname:
{
allow_numeric_hostname:
true
},
if: :enabled?
validates
:domain
,
allow_blank:
true
,
hostname:
{
allow_numeric_hostname:
true
}
def
variables
def
variables
variables
=
[]
variables
=
[]
...
...
app/services/ci/create_pipeline_service.rb
View file @
632f6ba2
...
@@ -72,7 +72,6 @@ module Ci
...
@@ -72,7 +72,6 @@ module Ci
unless
pipeline
.
ci_yaml_file
unless
pipeline
.
ci_yaml_file
return
error
(
"Missing
#{
pipeline
.
ci_yaml_file_path
}
file"
)
return
error
(
"Missing
#{
pipeline
.
ci_yaml_file_path
}
file"
)
end
end
return
error
(
pipeline
.
yaml_errors
,
save:
save_on_errors
)
return
error
(
pipeline
.
yaml_errors
,
save:
save_on_errors
)
end
end
...
...
spec/factories/project_auto_devops.rb
View file @
632f6ba2
...
@@ -2,5 +2,6 @@ FactoryGirl.define do
...
@@ -2,5 +2,6 @@ FactoryGirl.define do
factory
:project_auto_devops
do
factory
:project_auto_devops
do
project
project
enabled
true
enabled
true
domain
"example.com"
end
end
end
end
spec/models/ci/build_spec.rb
View file @
632f6ba2
...
@@ -1688,6 +1688,30 @@ describe Ci::Build do
...
@@ -1688,6 +1688,30 @@ describe Ci::Build do
{
key:
'secret'
,
value:
'value'
,
public:
false
}])
{
key:
'secret'
,
value:
'value'
,
public:
false
}])
end
end
end
end
context
'when using auto devops'
do
context
'and is enabled'
do
before
do
project
.
create_auto_devops!
(
enabled:
true
,
domain:
'example.com'
)
end
it
"includes AUTO_DEVOPS_DOMAIN"
do
is_expected
.
to
include
(
{
key:
'AUTO_DEVOPS_DOMAIN'
,
value:
'example.com'
,
public:
true
})
end
end
context
'and is disabled'
do
before
do
project
.
create_auto_devops!
(
enabled:
false
,
domain:
'example.com'
)
end
it
"includes AUTO_DEVOPS_DOMAIN"
do
is_expected
.
not_to
include
(
{
key:
'AUTO_DEVOPS_DOMAIN'
,
value:
'example.com'
,
public:
true
})
end
end
end
end
end
describe
'state transition: any => [:pending]'
do
describe
'state transition: any => [:pending]'
do
...
...
spec/models/ci/pipeline_spec.rb
View file @
632f6ba2
...
@@ -799,31 +799,64 @@ describe Ci::Pipeline, :mailer do
...
@@ -799,31 +799,64 @@ describe Ci::Pipeline, :mailer do
end
end
end
end
describe
'#detect_ci_yaml_file'
do
describe
'#set_config_source'
do
context
'when the repo has a config file'
do
context
'on object initialisation'
do
it
'returns that configuration'
do
context
'when pipelines does not contain needed data'
do
allow
(
pipeline
.
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
let
(
:pipeline
)
do
Ci
::
Pipeline
.
new
end
it
'defines source to be unknown'
do
expect
(
pipeline
).
to
be_unknown_source
end
end
context
'when pipeline contains all needed data'
do
let
(
:pipeline
)
do
Ci
::
Pipeline
.
new
(
project:
project
,
sha:
'1234'
,
ref:
'master'
,
source: :push
)
end
context
'when the repository has a config file'
do
before
do
allow
(
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
.
and_return
(
'config'
)
.
and_return
(
'config'
)
end
expect
(
pipeline
.
detect_ci_yaml_file
).
to
be_a
(
String
)
it
'defines source to be from repository'
do
expect
(
pipeline
.
repository_source?
).
to
be
(
true
)
expect
(
pipeline
).
to
be_repository_source
end
context
'when loading an object'
do
let
(
:new_pipeline
)
{
Ci
::
Pipeline
.
find
(
pipeline
.
id
)
}
it
'does not redefine the source'
do
# force to overwrite the source
pipeline
.
unknown_source!
expect
(
new_pipeline
).
to
be_unknown_source
end
end
end
end
end
context
'when the repo
does not have a config file'
do
context
'when the repository
does not have a config file'
do
let
(
:implied_yml
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
}
let
(
:implied_yml
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
}
context
'auto devops enabled'
do
context
'auto devops enabled'
do
before
do
before
do
allow_any_instance_of
(
ApplicationSetting
)
stub_application_setting
(
auto_devops_enabled:
true
)
.
to
receive
(
:auto_devops_enabled?
)
{
true
}
allow
(
project
).
to
receive
(
:ci_config_path
)
{
'custom'
}
end
end
it
'returns the implied ci file
'
do
it
'defines source to be auto devops
'
do
allow
(
pipeline
.
project
).
to
receive
(
:ci_config_path
)
{
'custom'
}
subject
expect
(
pipeline
.
detect_ci_yaml_file
).
to
eq
(
implied_yml
)
expect
(
pipeline
).
to
be_auto_devops_source
expect
(
pipeline
.
auto_devops_source?
).
to
be
(
true
)
end
end
end
end
end
end
end
end
...
@@ -870,13 +903,11 @@ describe Ci::Pipeline, :mailer do
...
@@ -870,13 +903,11 @@ describe Ci::Pipeline, :mailer do
context
'when the source is auto_devops_source'
do
context
'when the source is auto_devops_source'
do
before
do
before
do
stub_application_setting
(
auto_devops_enabled:
true
)
pipeline
.
auto_devops_source!
pipeline
.
auto_devops_source!
end
end
it
'finds the implied config'
do
it
'finds the implied config'
do
allow_any_instance_of
(
ApplicationSetting
)
.
to
receive
(
:auto_devops_enabled?
)
{
true
}
expect
(
pipeline
.
ci_yaml_file
).
to
eq
(
implied_yml
)
expect
(
pipeline
.
ci_yaml_file
).
to
eq
(
implied_yml
)
expect
(
pipeline
.
yaml_errors
).
to
be_nil
expect
(
pipeline
.
yaml_errors
).
to
be_nil
end
end
...
...
spec/models/project_auto_devops_spec.rb
View file @
632f6ba2
require
'spec_helper'
require
'spec_helper'
describe
ProjectAutoDevops
do
describe
ProjectAutoDevops
do
s
ubject
{
build_stubbed
(
:project_auto_devops
)
}
s
et
(
:project
)
{
build
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:domain
)
}
it
{
is_expected
.
to
respond_to
(
:created_at
)
}
it
{
is_expected
.
to
respond_to
(
:created_at
)
}
it
{
is_expected
.
to
respond_to
(
:updated_at
)
}
it
{
is_expected
.
to
respond_to
(
:updated_at
)
}
it
{
is_expected
.
to
be_enabled
}
describe
'variables'
do
let
(
:auto_devops
)
{
build_stubbed
(
:project_auto_devops
,
project:
project
,
domain:
domain
)
}
context
'when domain is defined'
do
let
(
:domain
)
{
'example.com'
}
it
'returns AUTO_DEVOPS_DOMAIN'
do
expect
(
auto_devops
.
variables
).
to
include
(
{
key:
'AUTO_DEVOPS_DOMAIN'
,
value:
'example.com'
,
public:
true
})
end
end
end
end
end
spec/models/project_spec.rb
View file @
632f6ba2
...
@@ -2509,4 +2509,133 @@ describe Project do
...
@@ -2509,4 +2509,133 @@ describe Project do
end
end
end
end
end
end
describe
'#has_ci?'
do
set
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
double
}
before
do
expect
(
project
).
to
receive
(
:repository
)
{
repository
}
end
context
'when has .gitlab-ci.yml'
do
before
do
expect
(
repository
).
to
receive
(
:gitlab_ci_yml
)
{
'content'
}
end
it
"CI is available"
do
expect
(
project
).
to
have_ci
end
end
context
'when there is no .gitlab-ci.yml'
do
before
do
expect
(
repository
).
to
receive
(
:gitlab_ci_yml
)
{
nil
}
end
it
"CI is not available"
do
expect
(
project
).
not_to
have_ci
end
context
'when auto devops is enabled'
do
before
do
stub_application_setting
(
auto_devops_enabled:
true
)
end
it
"CI is available"
do
expect
(
project
).
to
have_ci
end
end
end
end
describe
'#auto_devops_enabled?'
do
set
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
auto_devops_enabled?
}
context
'when enabled in settings'
do
before
do
stub_application_setting
(
auto_devops_enabled:
true
)
end
it
'auto devops is implicitly enabled'
do
expect
(
project
.
auto_devops
).
to
be_nil
expect
(
project
).
to
be_auto_devops_enabled
end
context
'when explicitly enabled'
do
before
do
create
(
:project_auto_devops
,
project:
project
)
end
it
"auto devops is enabled"
do
expect
(
project
).
to
be_auto_devops_enabled
end
end
context
'when explicitly disabled'
do
before
do
create
(
:project_auto_devops
,
project:
project
,
enabled:
false
)
end
it
"auto devops is disabled"
do
expect
(
project
).
not_to
be_auto_devops_enabled
end
end
end
context
'when disabled in settings'
do
before
do
stub_application_setting
(
auto_devops_enabled:
false
)
end
it
'auto devops is implicitly disabled'
do
expect
(
project
.
auto_devops
).
to
be_nil
expect
(
project
).
not_to
be_auto_devops_enabled
end
context
'when explicitly enabled'
do
before
do
create
(
:project_auto_devops
,
project:
project
)
end
it
"auto devops is enabled"
do
expect
(
project
).
to
be_auto_devops_enabled
end
end
end
end
context
'#auto_devops_variables'
do
set
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
auto_devops_variables
}
context
'when enabled in settings'
do
before
do
stub_application_setting
(
auto_devops_enabled:
true
)
end
context
'when domain is empty'
do
before
do
create
(
:project_auto_devops
,
project:
project
,
domain:
nil
)
end
it
'variables are empty'
do
is_expected
.
to
be_empty
end
end
context
'when domain is configured'
do
before
do
create
(
:project_auto_devops
,
project:
project
,
domain:
'example.com'
)
end
it
"variables are not empty"
do
is_expected
.
not_to
be_empty
end
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