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
Boxiang Sun
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
Show 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
...
@@ -9,17 +9,22 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
def
index
def
index
@scope
=
params
[
:scope
]
@environments
=
project
.
environments
@environments
=
project
.
environments
.
includes
(
:last_deployment
)
.
includes
(
:last_deployment
)
.
with_state
(
params
[
:scope
]
||
:available
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
format
.
json
do
format
.
json
do
render
json:
EnvironmentSerializer
render
json:
{
environments:
EnvironmentSerializer
.
new
(
project:
@project
,
user:
@current_user
)
.
new
(
project:
@project
,
user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
with_pagination
(
request
,
response
)
.
within_folders
.
within_folders
.
represent
(
@environments
)
.
represent
(
@environments
),
available_count:
project
.
environments
.
available
.
count
,
stopped_count:
project
.
environments
.
stopped
.
count
}
end
end
end
end
end
end
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
2aeb45bd
...
@@ -7,8 +7,7 @@ describe Projects::EnvironmentsController do
...
@@ -7,8 +7,7 @@ describe Projects::EnvironmentsController do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:environment
)
do
let
(
:environment
)
do
create
(
:environment
,
name:
'production'
,
create
(
:environment
,
name:
'production'
,
project:
project
)
project:
project
)
end
end
before
do
before
do
...
@@ -28,18 +27,56 @@ describe Projects::EnvironmentsController do
...
@@ -28,18 +27,56 @@ describe Projects::EnvironmentsController do
context
'when requesting JSON response for folders'
do
context
'when requesting JSON response for folders'
do
before
do
before
do
create
(
:environment
,
project:
project
,
name:
'staging/review-1'
)
create
(
:environment
,
project:
project
,
create
(
:environment
,
project:
project
,
name:
'staging/review-2'
)
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
end
it
'responds with correct JSON'
do
it
'contains values describing environment scopes sizes'
do
get
:index
,
environment_params
(
format: :json
)
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
end
end
context
'when requesting stopped environments scope'
do
before
do
get
:index
,
environment_params
(
format: :json
,
scope: :stopped
)
end
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
expect
(
json_response
.
count
).
to
eq
2
it
'contains values describing environment scopes sizes'
do
expect
(
json_response
.
first
[
'name'
]).
to
eq
'production'
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
.
second
[
'name'
]).
to
eq
'staging'
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
expect
(
json_response
.
second
[
'size'
]).
to
eq
2
end
expect
(
json_response
.
second
[
'latest'
][
'name'
]).
to
eq
'staging/review-2'
end
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