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
4a369185
Commit
4a369185
authored
Oct 17, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work on specs
parent
25dd1712
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
3 deletions
+140
-3
app/services/create_deployment_service.rb
app/services/create_deployment_service.rb
+2
-2
spec/models/deployment_spec.rb
spec/models/deployment_spec.rb
+46
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+32
-0
spec/services/create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+60
-1
No files found.
app/services/create_deployment_service.rb
View file @
4a369185
...
@@ -9,7 +9,7 @@ class CreateDeploymentService < BaseService
...
@@ -9,7 +9,7 @@ class CreateDeploymentService < BaseService
@environment
=
environment
@environment
=
environment
@environment
.
external_url
=
expanded_url
if
expanded_url
@environment
.
external_url
=
expanded_url
if
expanded_url
@environment
.
state_event
=
action
@environment
.
fire_state_event
(
action
)
@environment
.
save!
@environment
.
save!
return
if
@environment
.
stopped?
return
if
@environment
.
stopped?
...
@@ -68,6 +68,6 @@ class CreateDeploymentService < BaseService
...
@@ -68,6 +68,6 @@ class CreateDeploymentService < BaseService
end
end
def
action
def
action
params
[
:options
].
fetch
(
:action
,
'start'
)
options
[
:action
]
||
'start'
end
end
end
end
spec/models/deployment_spec.rb
View file @
4a369185
...
@@ -48,4 +48,50 @@ describe Deployment, models: true do
...
@@ -48,4 +48,50 @@ describe Deployment, models: true do
end
end
end
end
end
end
describe
'#stop_action'
do
let
(
:build
)
{
create
(
:ci_build
)
}
subject
{
deployment
.
stop_action
}
context
'when no other actions'
do
let
(
:deployment
)
{
FactoryGirl
.
build
(
:deployment
,
deployable:
build
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'with other actions'
do
let!
(
:close_action
)
{
create
(
:ci_build
,
pipeline:
build
.
pipeline
,
name:
'close_app'
,
when: :manual
)
}
context
'when matching action is defined'
do
let
(
:deployment
)
{
FactoryGirl
.
build
(
:deployment
,
deployable:
build
,
on_stop:
'close_other_app'
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when no matching action is defined'
do
let
(
:deployment
)
{
FactoryGirl
.
build
(
:deployment
,
deployable:
build
,
on_stop:
'close_app'
)
}
it
{
is_expected
.
to
eq
(
close_action
)
}
end
end
end
describe
'#stoppable?'
do
subject
{
deployment
.
stoppable?
}
context
'when no other actions'
do
let
(
:deployment
)
{
build
(
:deployment
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'when matching action is defined'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:deployment
)
{
FactoryGirl
.
build
(
:deployment
,
deployable:
build
,
on_stop:
'close_app'
)
}
let!
(
:close_action
)
{
create
(
:ci_build
,
pipeline:
build
.
pipeline
,
name:
'close_app'
,
when: :manual
)
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
spec/models/environment_spec.rb
View file @
4a369185
...
@@ -8,6 +8,8 @@ describe Environment, models: true do
...
@@ -8,6 +8,8 @@ describe Environment, models: true do
it
{
is_expected
.
to
delegate_method
(
:last_deployment
).
to
(
:deployments
).
as
(
:last
)
}
it
{
is_expected
.
to
delegate_method
(
:last_deployment
).
to
(
:deployments
).
as
(
:last
)
}
it
{
is_expected
.
to
delegate_method
(
:stop_action
).
to
(
:last_deployment
).
as
(
:last
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:project_id
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_within
(
0
..
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_within
(
0
..
255
)
}
...
@@ -96,4 +98,34 @@ describe Environment, models: true do
...
@@ -96,4 +98,34 @@ describe Environment, models: true do
is_expected
.
to
be_nil
is_expected
.
to
be_nil
end
end
end
end
describe
'#stoppable?'
do
subject
{
environment
.
stoppable?
}
context
'when no other actions'
do
it
{
is_expected
.
to
be_falsey
}
end
context
'when matching action is defined'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
deployable:
build
,
on_stop:
'close_app'
)
}
let!
(
:close_action
)
{
create
(
:ci_build
,
pipeline:
build
.
pipeline
,
name:
'close_app'
,
when: :manual
)
}
context
'when environment is available'
do
before
do
environment
.
start
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when environment is stopped'
do
before
do
environment
.
stop
end
it
{
is_expected
.
to
be_falsey
}
end
end
end
end
end
spec/services/create_deployment_service_spec.rb
View file @
4a369185
...
@@ -7,11 +7,13 @@ describe CreateDeploymentService, services: true do
...
@@ -7,11 +7,13 @@ describe CreateDeploymentService, services: true do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
describe
'#execute'
do
describe
'#execute'
do
let
(
:options
)
{
nil
}
let
(
:params
)
do
let
(
:params
)
do
{
environment:
'production'
,
{
environment:
'production'
,
ref:
'master'
,
ref:
'master'
,
tag:
false
,
tag:
false
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
,
options:
options
}
}
end
end
...
@@ -28,7 +30,7 @@ describe CreateDeploymentService, services: true do
...
@@ -28,7 +30,7 @@ describe CreateDeploymentService, services: true do
end
end
context
'when environment exist'
do
context
'when environment exist'
do
before
{
create
(
:environment
,
project:
project
,
name:
'production'
)
}
let!
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'production'
)
}
it
'does not create a new environment'
do
it
'does not create a new environment'
do
expect
{
subject
}.
not_to
change
{
Environment
.
count
}
expect
{
subject
}.
not_to
change
{
Environment
.
count
}
...
@@ -37,6 +39,46 @@ describe CreateDeploymentService, services: true do
...
@@ -37,6 +39,46 @@ describe CreateDeploymentService, services: true do
it
'does create a deployment'
do
it
'does create a deployment'
do
expect
(
subject
).
to
be_persisted
expect
(
subject
).
to
be_persisted
end
end
context
'and start action is defined'
do
let
(
:options
)
{
{
action:
'start'
}
}
context
'and environment is stopped'
do
before
do
environment
.
stop
end
it
'makes environment available'
do
subject
expect
(
environment
.
reload
).
to
be_available
end
it
'does not create a deployment'
do
expect
(
subject
).
not_to
be_persisted
end
end
end
context
'and stop action is defined'
do
let
(
:options
)
{
{
action:
'stop'
}
}
context
'and environment is available'
do
before
do
environment
.
start
end
it
'makes environment stopped'
do
subject
expect
(
environment
.
reload
).
to
be_stopped
end
it
'does not create a deployment'
do
expect
(
subject
).
to
be_nil
end
end
end
end
end
context
'for environment with invalid name'
do
context
'for environment with invalid name'
do
...
@@ -83,6 +125,23 @@ describe CreateDeploymentService, services: true do
...
@@ -83,6 +125,23 @@ describe CreateDeploymentService, services: true do
it
'does create a new deployment'
do
it
'does create a new deployment'
do
expect
(
subject
).
to
be_persisted
expect
(
subject
).
to
be_persisted
end
end
context
'and environment exist'
do
it
'does not create a new environment'
do
expect
{
subject
}.
not_to
change
{
Environment
.
count
}
end
it
'updates external url'
do
subject
expect
(
subject
.
environment
.
name
).
to
eq
(
'review-apps/feature-review-apps'
)
expect
(
subject
.
environment
.
external_url
).
to
eq
(
'http://feature-review-apps.review-apps.gitlab.com'
)
end
it
'does create a new deployment'
do
expect
(
subject
).
to
be_persisted
end
end
end
end
context
'when project was removed'
do
context
'when project was removed'
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