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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
f7ef7bea
Commit
f7ef7bea
authored
Nov 09, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add environment factory review app trait
parent
04a8372c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
22 deletions
+38
-22
app/services/ci/stop_environment_service.rb
app/services/ci/stop_environment_service.rb
+12
-7
spec/factories/deployments.rb
spec/factories/deployments.rb
+2
-1
spec/factories/environments.rb
spec/factories/environments.rb
+23
-0
spec/services/ci/stop_environment_service_spec.rb
spec/services/ci/stop_environment_service_spec.rb
+1
-14
No files found.
app/services/ci/stop_environment_service.rb
View file @
f7ef7bea
module
Ci
module
Ci
class
StopEnvironmentService
<
BaseService
class
StopEnvironmentService
<
BaseService
def
execute
(
ref
)
attr_reader
:ref
@ref
=
ref
@commit
=
project
.
commit
(
ref
)
return
unless
has_ref_sha_pair?
def
execute
(
branch_name
)
@ref
=
branch_name
return
unless
has_ref_commit_pair?
return
unless
has_environments?
return
unless
has_environments?
environments
.
each
do
|
environment
|
environments
.
each
do
|
environment
|
...
@@ -16,8 +17,12 @@ module Ci
...
@@ -16,8 +17,12 @@ module Ci
private
private
def
has_ref_sha_pair?
def
has_ref_commit_pair?
@ref
&&
@commit
ref
&&
commit
end
def
commit
@commit
||=
project
.
commit
(
ref
)
end
end
def
has_environments?
def
has_environments?
...
@@ -25,7 +30,7 @@ module Ci
...
@@ -25,7 +30,7 @@ module Ci
end
end
def
environments
def
environments
@environments
||=
project
.
environments_for
(
@ref
,
@
commit
)
@environments
||=
project
.
environments_for
(
ref
,
commit
)
end
end
end
end
end
end
spec/factories/deployments.rb
View file @
f7ef7bea
...
@@ -3,8 +3,9 @@ FactoryGirl.define do
...
@@ -3,8 +3,9 @@ FactoryGirl.define do
sha
'97de212e80737a608d939f648d959671fb0a0142'
sha
'97de212e80737a608d939f648d959671fb0a0142'
ref
'master'
ref
'master'
tag
false
tag
false
user
project
nil
project
nil
deployable
factory: :ci_build
environment
factory: :environment
environment
factory: :environment
after
(
:build
)
do
|
deployment
,
evaluator
|
after
(
:build
)
do
|
deployment
,
evaluator
|
...
...
spec/factories/environments.rb
View file @
f7ef7bea
...
@@ -4,5 +4,28 @@ FactoryGirl.define do
...
@@ -4,5 +4,28 @@ FactoryGirl.define do
project
factory: :empty_project
project
factory: :empty_project
sequence
(
:external_url
)
{
|
n
|
"https://env
#{
n
}
.example.gitlab.com"
}
sequence
(
:external_url
)
{
|
n
|
"https://env
#{
n
}
.example.gitlab.com"
}
trait
:with_review_app
do
|
environment
|
project
# At this point `review app` is an ephemeral concept related to
# deployments being deployed for given environment. There is no
# first-class `review app` available so we need to create set of
# interconnected objects to simulate a review app.
#
after
(
:create
)
do
|
environment
|
deployment
=
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
sha:
environment
.
project
.
commit
.
id
)
teardown_build
=
create
(
:ci_build
,
:manual
,
name:
"
#{
deployment
.
environment
.
name
}
:teardown"
,
pipeline:
deployment
.
deployable
.
pipeline
)
deployment
.
update_column
(
:on_stop
,
teardown_build
.
name
)
environment
.
update_attribute
(
:deployments
,
[
deployment
])
end
end
end
end
end
end
spec/services/ci/stop_environment_service_spec.rb
View file @
f7ef7bea
...
@@ -8,21 +8,8 @@ describe Ci::StopEnvironmentService, services: true do
...
@@ -8,21 +8,8 @@ describe Ci::StopEnvironmentService, services: true do
describe
'#execute'
do
describe
'#execute'
do
context
'when environment exists'
do
context
'when environment exists'
do
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:deployable
)
{
create
(
:ci_build
)
}
let
(
:stop_build
)
do
create
(
:ci_build
,
:manual
,
name:
'environment/teardown'
,
pipeline:
deployable
.
pipeline
)
end
before
do
before
do
create
(
:deployment
,
environment:
environment
,
create
(
:environment
,
:with_review_app
,
project:
project
)
deployable:
deployable
,
on_stop:
stop_build
.
name
,
user:
user
,
project:
project
,
sha:
project
.
commit
.
id
)
end
end
it
'stops environment'
do
it
'stops environment'
do
...
...
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