BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a5b96417
Commit
a5b96417
authored
Mar 11, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
with_status to represent_status
parent
3b635002
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
34 deletions
+31
-34
build_entity.rb
app/serializers/build_entity.rb
+1
-4
build_serializer.rb
app/serializers/build_serializer.rb
+5
-8
pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+5
-8
build_serializer_spec.rb
spec/serializers/build_serializer_spec.rb
+11
-7
pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+9
-7
No files found.
app/serializers/build_entity.rb
View file @
a5b96417
...
...
@@ -18,10 +18,7 @@ class BuildEntity < Grape::Entity
expose
:created_at
expose
:updated_at
expose
:details
do
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
end
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
private
...
...
app/serializers/build_serializer.rb
View file @
a5b96417
class
BuildSerializer
<
BaseSerializer
entity
BuildEntity
def
only_status
tap
{
@status_only
=
{
only:
[{
details:
[
:status
]
}]
}
}
end
def
represent
(
resource
,
opts
=
{})
if
@status_only
.
present?
opts
.
merge!
(
@status_only
)
end
super
(
resource
,
opts
)
end
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
[
:status
]
end
end
app/serializers/pipeline_serializer.rb
View file @
a5b96417
...
...
@@ -11,23 +11,20 @@ class PipelineSerializer < BaseSerializer
@paginator
.
present?
end
def
only_status
tap
{
@status_only
=
{
only:
[{
details:
[
:status
]
}]
}
}
end
def
represent
(
resource
,
opts
=
{})
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
resource
=
resource
.
includes
(
project: :namespace
)
end
if
@status_only
.
present?
opts
.
merge!
(
@status_only
)
end
if
paginated?
super
(
@paginator
.
paginate
(
resource
),
opts
)
else
super
(
resource
,
opts
)
end
end
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[{
details:
[
:status
]
}]
})
data
[
:details
][
:status
]
end
end
spec/serializers/build_serializer_spec.rb
View file @
a5b96417
...
...
@@ -10,16 +10,20 @@ describe BuildSerializer do
subject
{
serializer
.
represent
(
resource
)
}
describe
'#represent'
do
context
'when used with status'
do
let
(
:serializer
)
do
described_class
.
new
(
user:
user
)
.
only_status
# TODO:
end
describe
'#represent_status'
do
context
'when represents only status'
do
let
(
:status
)
do
Gitlab
::
Ci
::
Status
::
Success
.
new
(
double
(
'object'
),
double
(
'user'
))
end
let
(
:resource
)
{
create
(
:ci_build
)
}
let
(
:resource
)
{
create
(
:ci_build
,
status: :success
)
}
subject
{
serializer
.
represent_status
(
resource
)
}
it
'serializes only status'
do
expect
(
subject
[
:details
][
:status
]).
not_to
be_empty
expect
(
subject
[
:details
].
keys
.
count
).
to
eq
1
expect
(
subject
[
:favicon
]).
to
eq
(
status
.
favicon
)
end
end
end
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
a5b96417
...
...
@@ -93,17 +93,19 @@ describe PipelineSerializer do
end
end
end
end
context
'when used with
status'
do
let
(
:serializer
)
do
described_class
.
new
(
user:
user
)
.
only_status
describe
'#represent_
status'
do
context
'when represents only status'
do
let
(
:status
)
do
Gitlab
::
Ci
::
Status
::
Success
.
new
(
double
(
'object'
),
double
(
'user'
))
end
let
(
:resource
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:resource
)
{
create
(
:ci_pipeline
,
status: :success
)
}
subject
{
serializer
.
represent_status
(
resource
)
}
it
'serializes only status'
do
expect
(
subject
[
:details
][
:status
]).
not_to
be_empty
expect
(
subject
[
:details
].
keys
.
count
).
to
eq
1
expect
(
subject
[
:favicon
]).
to
eq
(
status
.
favicon
)
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