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
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
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
34 deletions
+31
-34
app/serializers/build_entity.rb
app/serializers/build_entity.rb
+1
-4
app/serializers/build_serializer.rb
app/serializers/build_serializer.rb
+5
-8
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+5
-8
spec/serializers/build_serializer_spec.rb
spec/serializers/build_serializer_spec.rb
+11
-7
spec/serializers/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
...
@@ -18,10 +18,7 @@ class BuildEntity < Grape::Entity
expose
:created_at
expose
:created_at
expose
:updated_at
expose
:updated_at
expose
:details
do
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
end
private
private
...
...
app/serializers/build_serializer.rb
View file @
a5b96417
class
BuildSerializer
<
BaseSerializer
class
BuildSerializer
<
BaseSerializer
entity
BuildEntity
entity
BuildEntity
def
only_status
tap
{
@status_only
=
{
only:
[{
details:
[
:status
]
}]
}
}
end
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
if
@status_only
.
present?
super
(
resource
,
opts
)
opts
.
merge!
(
@status_only
)
end
end
super
(
resource
,
opts
)
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
[
:status
]
end
end
end
end
app/serializers/pipeline_serializer.rb
View file @
a5b96417
...
@@ -11,23 +11,20 @@ class PipelineSerializer < BaseSerializer
...
@@ -11,23 +11,20 @@ class PipelineSerializer < BaseSerializer
@paginator
.
present?
@paginator
.
present?
end
end
def
only_status
tap
{
@status_only
=
{
only:
[{
details:
[
:status
]
}]
}
}
end
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
resource
=
resource
.
includes
(
project: :namespace
)
resource
=
resource
.
includes
(
project: :namespace
)
end
end
if
@status_only
.
present?
opts
.
merge!
(
@status_only
)
end
if
paginated?
if
paginated?
super
(
@paginator
.
paginate
(
resource
),
opts
)
super
(
@paginator
.
paginate
(
resource
),
opts
)
else
else
super
(
resource
,
opts
)
super
(
resource
,
opts
)
end
end
end
end
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[{
details:
[
:status
]
}]
})
data
[
:details
][
:status
]
end
end
end
spec/serializers/build_serializer_spec.rb
View file @
a5b96417
...
@@ -10,16 +10,20 @@ describe BuildSerializer do
...
@@ -10,16 +10,20 @@ describe BuildSerializer do
subject
{
serializer
.
represent
(
resource
)
}
subject
{
serializer
.
represent
(
resource
)
}
describe
'#represent'
do
describe
'#represent'
do
context
'when used with status'
do
# TODO:
let
(
:serializer
)
do
described_class
.
new
(
user:
user
)
.
only_status
end
end
let
(
:resource
)
{
create
(
:ci_build
)
}
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
,
status: :success
)
}
subject
{
serializer
.
represent_status
(
resource
)
}
it
'serializes only status'
do
it
'serializes only status'
do
expect
(
subject
[
:details
][
:status
]).
not_to
be_empty
expect
(
subject
[
:favicon
]).
to
eq
(
status
.
favicon
)
expect
(
subject
[
:details
].
keys
.
count
).
to
eq
1
end
end
end
end
end
end
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
a5b96417
...
@@ -93,17 +93,19 @@ describe PipelineSerializer do
...
@@ -93,17 +93,19 @@ describe PipelineSerializer do
end
end
end
end
end
end
end
context
'when used with
status'
do
describe
'#represent_
status'
do
let
(
:serializer
)
do
context
'when represents only status'
do
described_class
.
new
(
user:
user
)
let
(
:status
)
do
.
only_status
Gitlab
::
Ci
::
Status
::
Success
.
new
(
double
(
'object'
),
double
(
'user'
))
end
end
let
(
:resource
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:resource
)
{
create
(
:ci_pipeline
,
status: :success
)
}
subject
{
serializer
.
represent_status
(
resource
)
}
it
'serializes only status'
do
it
'serializes only status'
do
expect
(
subject
[
:details
][
:status
]).
not_to
be_empty
expect
(
subject
[
:favicon
]).
to
eq
(
status
.
favicon
)
expect
(
subject
[
:details
].
keys
.
count
).
to
eq
1
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