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
d0d94e4f
Commit
d0d94e4f
authored
Feb 10, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pagination headers in grouped environments API
parent
482e7ff0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
app/serializers/environment_serializer.rb
app/serializers/environment_serializer.rb
+14
-9
spec/serializers/environment_serializer_spec.rb
spec/serializers/environment_serializer_spec.rb
+11
-0
No files found.
app/serializers/environment_serializer.rb
View file @
d0d94e4f
...
...
@@ -20,8 +20,6 @@ class EnvironmentSerializer < BaseSerializer
end
def
represent
(
resource
,
opts
=
{})
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
if
itemized?
itemize
(
resource
).
map
do
|
item
|
{
name:
item
.
name
,
...
...
@@ -29,6 +27,8 @@ class EnvironmentSerializer < BaseSerializer
latest:
super
(
item
.
latest
,
opts
)
}
end
else
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
super
(
resource
,
opts
)
end
end
...
...
@@ -36,15 +36,20 @@ class EnvironmentSerializer < BaseSerializer
private
def
itemize
(
resource
)
items
=
resource
.
group
(
:item_name
).
order
(
'item_name ASC'
)
.
pluck
(
'COALESCE(environment_type, name) AS item_name'
,
'COUNT(*) AS environments_count'
,
'MAX(id) AS last_environment_id'
)
items
=
resource
.
order
(
'folder_name ASC'
)
.
group
(
'COALESCE(environment_type, name)'
)
.
select
(
'COALESCE(environment_type, name) AS folder_name'
,
'COUNT(*) AS size'
,
'MAX(id) AS last_id'
)
# It makes a difference when you call `paginate` method, because
# although `page` is effective at the end, it calls counting methods
# immediately.
items
=
@paginator
.
paginate
(
items
)
if
paginated?
environments
=
resource
.
where
(
id:
items
.
map
(
&
:last
)).
index_by
(
&
:id
)
environments
=
resource
.
where
(
id:
items
.
map
(
&
:last
_id
)).
index_by
(
&
:id
)
items
.
map
do
|
name
,
size
,
id
|
Item
.
new
(
name
,
size
,
environments
[
id
])
items
.
map
do
|
item
|
Item
.
new
(
item
.
folder_name
,
item
.
size
,
environments
[
item
.
last_
id
])
end
end
end
spec/serializers/environment_serializer_spec.rb
View file @
d0d94e4f
...
...
@@ -181,6 +181,17 @@ describe EnvironmentSerializer do
expect
(
subject
.
first
[
:name
]).
to
eq
'production'
expect
(
subject
.
second
[
:name
]).
to
eq
'staging'
end
it
'appends correct total page count header'
do
expect
(
subject
).
not_to
be_empty
expect
(
response
).
to
have_received
(
:[]=
).
with
(
'X-Total'
,
'3'
)
end
it
'appends correct page count headers'
do
expect
(
subject
).
not_to
be_empty
expect
(
response
).
to
have_received
(
:[]=
).
with
(
'X-Total-Pages'
,
'2'
)
expect
(
response
).
to
have_received
(
:[]=
).
with
(
'X-Per-Page'
,
'2'
)
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