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
25c10abb
Commit
25c10abb
authored
Feb 26, 2019
by
Vladimir Shushlin
Committed by
Stan Hu
Feb 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add name_without_type to environments.json
It's needed to show shorter names in environments "folders"
parent
98120065
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
5 deletions
+33
-5
app/models/environment.rb
app/models/environment.rb
+4
-0
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+1
-0
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+5
-5
spec/fixtures/api/schemas/environment.json
spec/fixtures/api/schemas/environment.json
+1
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+22
-0
No files found.
app/models/environment.rb
View file @
25c10abb
...
@@ -243,6 +243,10 @@ class Environment < ActiveRecord::Base
...
@@ -243,6 +243,10 @@ class Environment < ActiveRecord::Base
self
.
environment_type
||
self
.
name
self
.
environment_type
||
self
.
name
end
end
def
name_without_type
@name_without_type
||=
name
.
delete_prefix
(
"
#{
environment_type
}
/"
)
end
def
deployment_platform
def
deployment_platform
strong_memoize
(
:deployment_platform
)
do
strong_memoize
(
:deployment_platform
)
do
project
.
deployment_platform
(
environment:
self
.
name
)
project
.
deployment_platform
(
environment:
self
.
name
)
...
...
app/serializers/environment_entity.rb
View file @
25c10abb
...
@@ -8,6 +8,7 @@ class EnvironmentEntity < Grape::Entity
...
@@ -8,6 +8,7 @@ class EnvironmentEntity < Grape::Entity
expose
:state
expose
:state
expose
:external_url
expose
:external_url
expose
:environment_type
expose
:environment_type
expose
:name_without_type
expose
:last_deployment
,
using:
DeploymentEntity
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stop_action_available?
,
as: :has_stop_action
expose
:stop_action_available?
,
as: :has_stop_action
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
25c10abb
...
@@ -54,9 +54,9 @@ describe Projects::EnvironmentsController do
...
@@ -54,9 +54,9 @@ describe Projects::EnvironmentsController do
it
'responds with a flat payload describing available environments'
do
it
'responds with a flat payload describing available environments'
do
expect
(
environments
.
count
).
to
eq
3
expect
(
environments
.
count
).
to
eq
3
expect
(
environments
.
first
[
'name'
]).
to
eq
'production'
expect
(
environments
.
first
).
to
include
(
'name'
=>
'production'
,
'name_without_type'
=>
'production'
)
expect
(
environments
.
second
[
'name'
]).
to
eq
'staging/review-1'
expect
(
environments
.
second
).
to
include
(
'name'
=>
'staging/review-1'
,
'name_without_type'
=>
'review-1'
)
expect
(
environments
.
third
[
'name'
]).
to
eq
'staging/review-2'
expect
(
environments
.
third
).
to
include
(
'name'
=>
'staging/review-2'
,
'name_without_type'
=>
'review-2'
)
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
[
'available_count'
]).
to
eq
3
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
end
end
...
@@ -155,9 +155,9 @@ describe Projects::EnvironmentsController do
...
@@ -155,9 +155,9 @@ describe Projects::EnvironmentsController do
expect
(
response
).
to
be_ok
expect
(
response
).
to
be_ok
expect
(
response
).
not_to
render_template
'folder'
expect
(
response
).
not_to
render_template
'folder'
expect
(
json_response
[
'environments'
][
0
])
expect
(
json_response
[
'environments'
][
0
])
.
to
include
(
'name'
=>
'staging-1.0/review'
)
.
to
include
(
'name'
=>
'staging-1.0/review'
,
'name_without_type'
=>
'review'
)
expect
(
json_response
[
'environments'
][
1
])
expect
(
json_response
[
'environments'
][
1
])
.
to
include
(
'name'
=>
'staging-1.0/zzz'
)
.
to
include
(
'name'
=>
'staging-1.0/zzz'
,
'name_without_type'
=>
'zzz'
)
end
end
end
end
end
end
...
...
spec/fixtures/api/schemas/environment.json
View file @
25c10abb
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
"state"
:
{
"type"
:
"string"
},
"state"
:
{
"type"
:
"string"
},
"external_url"
:
{
"$ref"
:
"types/nullable_string.json"
},
"external_url"
:
{
"$ref"
:
"types/nullable_string.json"
},
"environment_type"
:
{
"$ref"
:
"types/nullable_string.json"
},
"environment_type"
:
{
"$ref"
:
"types/nullable_string.json"
},
"name_without_type"
:
{
"type"
:
"string"
},
"has_stop_action"
:
{
"type"
:
"boolean"
},
"has_stop_action"
:
{
"type"
:
"boolean"
},
"environment_path"
:
{
"type"
:
"string"
},
"environment_path"
:
{
"type"
:
"string"
},
"stop_path"
:
{
"type"
:
"string"
},
"stop_path"
:
{
"type"
:
"string"
},
...
...
spec/models/environment_spec.rb
View file @
25c10abb
...
@@ -164,6 +164,28 @@ describe Environment do
...
@@ -164,6 +164,28 @@ describe Environment do
end
end
end
end
describe
'#name_without_type'
do
context
'when it is inside a folder'
do
subject
(
:environment
)
do
create
(
:environment
,
name:
'staging/review-1'
)
end
it
'returns name without folder'
do
expect
(
environment
.
name_without_type
).
to
eq
'review-1'
end
end
context
'when the environment if a top-level item itself'
do
subject
(
:environment
)
do
create
(
:environment
,
name:
'production'
)
end
it
'returns full name'
do
expect
(
environment
.
name_without_type
).
to
eq
'production'
end
end
end
describe
'#nullify_external_url'
do
describe
'#nullify_external_url'
do
it
'replaces a blank url with nil'
do
it
'replaces a blank url with nil'
do
env
=
build
(
:environment
,
external_url:
""
)
env
=
build
(
:environment
,
external_url:
""
)
...
...
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