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
e9880722
Commit
e9880722
authored
Oct 17, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix environments specs
parent
4a369185
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
74 additions
and
32 deletions
+74
-32
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+3
-2
app/models/environment.rb
app/models/environment.rb
+3
-0
app/services/create_deployment_service.rb
app/services/create_deployment_service.rb
+1
-1
app/views/projects/environments/_external_url.html.haml
app/views/projects/environments/_external_url.html.haml
+1
-1
app/views/projects/environments/_stop.html.haml
app/views/projects/environments/_stop.html.haml
+1
-1
app/views/projects/environments/show.html.haml
app/views/projects/environments/show.html.haml
+3
-5
spec/features/environments_spec.rb
spec/features/environments_spec.rb
+57
-19
spec/services/create_deployment_service_spec.rb
spec/services/create_deployment_service_spec.rb
+5
-3
No files found.
app/controllers/projects/environments_controller.rb
View file @
e9880722
class
Projects::EnvironmentsController
<
Projects
::
ApplicationController
layout
'project'
before_action
:authorize_read_environment!
before_action
:authorize_create_environment!
,
only:
[
:new
,
:create
]
before_action
:authorize_update_environment!
,
only:
[
:edit
,
:update
,
:stop
]
before_action
:authorize_create_environment!
,
only:
[
:new
,
:create
,
:stop
]
before_action
:authorize_create_deployment!
,
only:
[
:stop
]
before_action
:authorize_update_environment!
,
only:
[
:edit
,
:update
]
before_action
:environment
,
only:
[
:show
,
:edit
,
:update
,
:stop
]
def
index
...
...
app/models/environment.rb
View file @
e9880722
...
...
@@ -21,6 +21,9 @@ class Environment < ActiveRecord::Base
delegate
:stop_action
,
to: :last_deployment
,
allow_nil:
true
scope
:available
,
->
{
with_state
(
:available
)
}
scope
:stopped
,
->
{
with_state
(
:stopped
)
}
state_machine
:state
,
initial: :available
do
event
:start
do
transition
stopped: :available
...
...
app/services/create_deployment_service.rb
View file @
e9880722
...
...
@@ -10,8 +10,8 @@ class CreateDeploymentService < BaseService
@environment
=
environment
@environment
.
external_url
=
expanded_url
if
expanded_url
@environment
.
fire_state_event
(
action
)
@environment
.
save!
return
unless
@environment
.
save
return
if
@environment
.
stopped?
deploy
.
tap
do
|
deployment
|
...
...
app/views/projects/environments/_external_url.html.haml
View file @
e9880722
-
if
environment
.
external_url
-
if
environment
.
external_url
&&
can?
(
current_user
,
:read_environment
,
environment
)
=
link_to
environment
.
external_url
,
target:
'_blank'
,
class:
'btn external-url'
do
=
icon
(
'external-link'
)
app/views/projects/environments/_stop.html.haml
View file @
e9880722
-
if
environment
.
stoppable?
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
stoppable?
.inline
=
link_to
stop_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
),
method: :post
,
class:
'btn close-env-link'
,
rel:
'nofollow'
,
data:
{
confirm:
'Are you sure you want to stop this environment?'
}
do
...
...
app/views/projects/environments/show.html.haml
View file @
e9880722
...
...
@@ -8,12 +8,10 @@
%h3
.page-title
=
@environment
.
name
.
capitalize
.col-md-3
.nav-controls
-
if
can?
(
current_user
,
:read_environmnet
,
@environment
)
=
render
'projects/environments/external_url'
,
environment:
@environment
-
if
can?
(
current_user
,
:update_environment
,
@environment
)
=
link_to
'Edit'
,
edit_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
class:
'btn'
-
if
@environment
.
stoppable?
-
if
can?
(
current_user
,
:create_deployment
,
@environment
)
&&
@environment
.
stoppable?
=
link_to
'Stop'
,
stop_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
data:
{
confirm:
'Are you sure you want to stop this environment?'
},
class:
'btn btn-danger'
,
method: :post
.deployments-container
...
...
spec/features/environments_spec.rb
View file @
e9880722
...
...
@@ -35,7 +35,7 @@ feature 'Environments', feature: true do
end
scenario
'does show 0 as counter for environments in both tabs'
do
expect
(
page
.
find
(
'.js-avai
ba
le-environments-count'
).
text
).
to
eq
(
'0'
)
expect
(
page
.
find
(
'.js-avai
lab
le-environments-count'
).
text
).
to
eq
(
'0'
)
expect
(
page
.
find
(
'.js-stopped-environments-count'
).
text
).
to
eq
(
'0'
)
end
end
...
...
@@ -48,7 +48,7 @@ feature 'Environments', feature: true do
end
scenario
'does show number of opened environments in Availabe tab'
do
expect
(
page
.
find
(
'.js-avai
ba
le-environments-count'
).
text
).
to
eq
(
'1'
)
expect
(
page
.
find
(
'.js-avai
lab
le-environments-count'
).
text
).
to
eq
(
'1'
)
end
scenario
'does show number of closed environments in Stopped tab'
do
...
...
@@ -93,6 +93,14 @@ feature 'Environments', feature: true do
expect
(
page
).
to
have_link
(
"
#{
build
.
name
}
(#
#{
build
.
id
}
)"
)
end
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_selector
(
'.close-env-link'
)
end
scenario
'does not show external link button'
do
expect
(
page
).
not_to
have_css
(
'external-url'
)
end
context
'with external_url'
do
given
(
:environment
)
{
create
(
:environment
,
project:
project
,
external_url:
'https://git.gitlab.com'
)
}
given
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
...
...
@@ -103,14 +111,27 @@ feature 'Environments', feature: true do
end
end
scenario
'does show close button'
do
# TODO: Add test to verify if close button is visible
# This needs to be true: if local_assigns.fetch(:allow_close, false) && deployment.closeable?
context
'with stop action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'close_app'
)
}
given
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
deployable:
build
,
on_stop:
'close_app'
)
}
scenario
'does show stop button'
do
expect
(
page
).
to
have_selector
(
'.close-env-link'
)
end
scenario
'does allow to stop environment'
do
first
(
'.close-env-link'
).
click
expect
(
page
).
to
have_content
(
'close_app'
)
end
scenario
'does allow to close environment'
do
# TODO: Add test to verify if close environment works
# This needs to be true: if local_assigns.fetch(:allow_close, false) && deployment.closeable?
context
'for reporter'
do
let
(
:role
)
{
:reporter
}
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_selector
(
'.close-env-link'
)
end
end
end
end
end
...
...
@@ -160,6 +181,10 @@ feature 'Environments', feature: true do
expect
(
page
).
to
have_link
(
'Re-deploy'
)
end
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
context
'with manual action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'deploy to production'
)
}
...
...
@@ -184,14 +209,27 @@ feature 'Environments', feature: true do
end
end
scenario
'does show close button'
do
# TODO: Add test to verify if close button is visible
# This needs to be true: if local_assigns.fetch(:allow_close, false) && deployment.closeable?
context
'with stop action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'close_app'
)
}
given
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
deployable:
build
,
on_stop:
'close_app'
)
}
scenario
'does show stop button'
do
expect
(
page
).
to
have_link
(
'Stop'
)
end
scenario
'does allow to stop environment'
do
click_link
(
'Stop'
)
expect
(
page
).
to
have_content
(
'close_app'
)
end
scenario
'does allow to close environment'
do
# TODO: Add test to verify if close environment works
# This needs to be true: if local_assigns.fetch(:allow_close, false) && deployment.closeable?
context
'for reporter'
do
let
(
:role
)
{
:reporter
}
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
end
end
end
end
...
...
spec/services/create_deployment_service_spec.rb
View file @
e9880722
...
...
@@ -54,8 +54,8 @@ describe CreateDeploymentService, services: true do
expect
(
environment
.
reload
).
to
be_available
end
it
'does
not
create a deployment'
do
expect
(
subject
).
not_
to
be_persisted
it
'does create a deployment'
do
expect
(
subject
).
to
be_persisted
end
end
end
...
...
@@ -95,7 +95,7 @@ describe CreateDeploymentService, services: true do
end
it
'does not create a deployment'
do
expect
(
subject
).
not_to
be_persisted
expect
(
subject
).
to
be_nil
end
end
...
...
@@ -127,6 +127,8 @@ describe CreateDeploymentService, services: true do
end
context
'and environment exist'
do
let!
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'review-apps/feature-review-apps'
)
}
it
'does not create a new environment'
do
expect
{
subject
}.
not_to
change
{
Environment
.
count
}
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