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
2aeb45bd
Commit
2aeb45bd
authored
Feb 04, 2017
by
Grzegorz Bizon
Committed by
Filipa Lacerda
Feb 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for environment scopes in controller
parent
b3309bb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
18 deletions
+60
-18
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+12
-7
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+48
-11
No files found.
app/controllers/projects/environments_controller.rb
View file @
2aeb45bd
...
...
@@ -9,17 +9,22 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
def
index
@scope
=
params
[
:scope
]
@environments
=
project
.
environments
.
includes
(
:last_deployment
)
@environments
=
project
.
environments
.
includes
(
:last_deployment
)
.
with_state
(
params
[
:scope
]
||
:available
)
respond_to
do
|
format
|
format
.
html
format
.
json
do
render
json:
EnvironmentSerializer
.
new
(
project:
@project
,
user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
within_folders
.
represent
(
@environments
)
render
json:
{
environments:
EnvironmentSerializer
.
new
(
project:
@project
,
user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
within_folders
.
represent
(
@environments
),
available_count:
project
.
environments
.
available
.
count
,
stopped_count:
project
.
environments
.
stopped
.
count
}
end
end
end
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
2aeb45bd
...
...
@@ -7,8 +7,7 @@ describe Projects::EnvironmentsController do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:environment
)
do
create
(
:environment
,
name:
'production'
,
project:
project
)
create
(
:environment
,
name:
'production'
,
project:
project
)
end
before
do
...
...
@@ -28,18 +27,56 @@ describe Projects::EnvironmentsController do
context
'when requesting JSON response for folders'
do
before
do
create
(
:environment
,
project:
project
,
name:
'staging/review-1'
)
create
(
:environment
,
project:
project
,
name:
'staging/review-2'
)
create
(
:environment
,
project:
project
,
name:
'staging/review-1'
,
state: :available
)
create
(
:environment
,
project:
project
,
name:
'staging/review-2'
,
state: :available
)
create
(
:environment
,
project:
project
,
name:
'staging/review-3'
,
state: :stopped
)
end
let
(
:environments
)
{
json_response
[
'environments'
]
}
context
'when requesting available environments scope'
do
before
do
get
:index
,
environment_params
(
format: :json
,
scope: :available
)
end
it
'responds with a payload describing available environments'
do
expect
(
environments
.
count
).
to
eq
2
expect
(
environments
.
first
[
'name'
]).
to
eq
'production'
expect
(
environments
.
second
[
'name'
]).
to
eq
'staging'
expect
(
environments
.
second
[
'size'
]).
to
eq
2
expect
(
environments
.
second
[
'latest'
][
'name'
]).
to
eq
'staging/review-2'
end
it
'contains values describing environment scopes sizes'
do
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
end
end
it
'responds with correct JSON'
do
get
:index
,
environment_params
(
format: :json
)
context
'when requesting stopped environments scope'
do
before
do
get
:index
,
environment_params
(
format: :json
,
scope: :stopped
)
end
expect
(
json_response
.
count
).
to
eq
2
expect
(
json_response
.
first
[
'name'
]).
to
eq
'production'
expect
(
json_response
.
second
[
'name'
]).
to
eq
'staging'
expect
(
json_response
.
second
[
'size'
]).
to
eq
2
expect
(
json_response
.
second
[
'latest'
][
'name'
]).
to
eq
'staging/review-2'
it
'responds with a payload describing stopped environments'
do
expect
(
environments
.
count
).
to
eq
1
expect
(
environments
.
first
[
'name'
]).
to
eq
'staging'
expect
(
environments
.
first
[
'size'
]).
to
eq
1
expect
(
environments
.
first
[
'latest'
][
'name'
]).
to
eq
'staging/review-3'
end
it
'contains values describing environment scopes sizes'
do
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
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