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
f1e9c97d
Commit
f1e9c97d
authored
Nov 02, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use entity request object in environment entity
parent
acfe3940
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
18 deletions
+22
-18
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+11
-3
app/serializers/project_entity.rb
app/serializers/project_entity.rb
+3
-1
app/serializers/request_aware_entity.rb
app/serializers/request_aware_entity.rb
+0
-5
spec/serializers/environment_serializer_spec.rb
spec/serializers/environment_serializer_spec.rb
+8
-9
No files found.
app/serializers/environment_entity.rb
View file @
f1e9c97d
...
...
@@ -9,9 +9,17 @@ class EnvironmentEntity < Grape::Entity
as: :deployment
,
using:
API
::
Entities
::
Deployment
expose
:environment_path
expose
:gitlab_path
do
|
environment
|
namespace_project_environment_path
(
environment
.
project
.
namespace
,
environment
.
project
,
environment
)
end
expose
:can_read?
def
environment_path
request
.
path
def
can_read?
Ability
.
allowed?
(
request
.
user
,
:read_environment
,
@object
)
end
end
app/serializers/project_entity.rb
View file @
f1e9c97d
class
ProjectEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:name
expose
:test
do
|
project
|
'something'
request
.
user
.
email
end
end
app/serializers/request_aware_entity.rb
View file @
f1e9c97d
module
RequestAwareEntity
# We use SerializableRequest class to collect parameters and variables
# from the controller. Because options that are being passed to the entity
# are appear in each entity in the chain, we need a way to access data
# that is present in the controller (see #20045).
#
def
request
options
[
:request
]
||
raise
(
StandardError
,
'Request not set!!'
)
...
...
spec/serializers/environment_serializer_spec.rb
View file @
f1e9c97d
...
...
@@ -2,18 +2,21 @@ require 'spec_helper'
describe
EnvironmentSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
path:
'some path'
).
represent
(
resource
)
described_class
.
new
(
path:
'some path'
,
user:
user
)
.
represent
(
resource
)
end
let
(
:user
)
{
create
(
:user
)
}
context
'when there is a single object provided'
do
let
(
:resource
)
{
create
(
:environment
)
}
it
'shows json'
do
puts
serializer
.
to
_json
puts
serializer
.
as
_json
end
it
'it generates payload for single object'
do
expect
(
parsed
_json
).
to
be_an_instance_of
Hash
expect
(
serializer
.
as
_json
).
to
be_an_instance_of
Hash
end
end
...
...
@@ -21,15 +24,11 @@ describe EnvironmentSerializer do
let
(
:resource
)
{
create_list
(
:environment
,
2
)
}
it
'shows json'
do
puts
serializer
.
to
_json
puts
serializer
.
as
_json
end
it
'generates payload for collection'
do
expect
(
parsed
_json
).
to
be_an_instance_of
Array
expect
(
serializer
.
as
_json
).
to
be_an_instance_of
Array
end
end
def
parsed_json
JSON
.
parse
(
serializer
.
to_json
)
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