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
Tatuya Kamada
gitlab-ce
Commits
0aa23270
Commit
0aa23270
authored
Oct 18, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `stop!` to `environment`
parent
66ff67b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
4 deletions
+50
-4
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+7
-4
app/models/environment.rb
app/models/environment.rb
+6
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+37
-0
No files found.
app/controllers/projects/environments_controller.rb
View file @
0aa23270
...
...
@@ -9,8 +9,12 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def
index
@scope
=
params
[
:scope
]
@all_environments
=
project
.
environments
@environments
=
@scope
==
'stopped'
?
@all_environments
.
stopped
:
@all_environments
.
available
@environments
=
if
@scope
==
'stopped'
then
@all_environments
.
stopped
else
@all_environments
.
available
end
end
def
show
...
...
@@ -45,8 +49,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def
stop
return
render_404
unless
@environment
.
stoppable?
action
=
@environment
.
stop_action
new_action
=
action
.
active?
?
action
:
action
.
play
(
current_user
)
new_action
=
@environment
.
stop!
(
current_user
)
redirect_to
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
new_action
])
end
...
...
app/models/environment.rb
View file @
0aa23270
...
...
@@ -88,4 +88,10 @@ class Environment < ActiveRecord::Base
def
stoppable?
available?
&&
stop_action
.
present?
end
def
stop!
(
current_user
)
return
unless
stoppable?
stop_action
.
play
(
current_user
)
end
end
spec/models/environment_spec.rb
View file @
0aa23270
...
...
@@ -128,4 +128,41 @@ describe Environment, models: true do
end
end
end
describe
'#stop!'
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
environment
.
stop!
(
user
)
}
before
do
expect
(
environment
).
to
receive
(
:stoppable?
).
and_call_original
end
context
'when no other actions'
do
it
{
is_expected
.
to
be_nil
}
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'
)
}
context
'when action did not yet finish'
do
let!
(
:close_action
)
{
create
(
:ci_build
,
:manual
,
pipeline:
build
.
pipeline
,
name:
'close_app'
)
}
it
'returns the same action'
do
is_expected
.
to
eq
(
close_action
)
is_expected
.
to
include
(
user:
user
)
end
end
context
'if action did finish'
do
let!
(
:close_action
)
{
create
(
:ci_build
,
:manual
,
:success
,
pipeline:
build
.
pipeline
,
name:
'close_app'
)
}
it
'returns a new action of the same type'
do
is_expected
.
to
be_persisted
is_expected
.
to
include
(
name:
close_action
.
name
,
user:
user
)
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