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
eccfab44
Commit
eccfab44
authored
Feb 16, 2019
by
Nermin Vehabovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added: Specs for sort page breaks on notes
parent
44b2d759
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
11 deletions
+43
-11
lib/api/helpers.rb
lib/api/helpers.rb
+6
-6
spec/support/shared_examples/requests/api/notes.rb
spec/support/shared_examples/requests/api/notes.rb
+37
-5
No files found.
lib/api/helpers.rb
View file @
eccfab44
...
...
@@ -299,6 +299,12 @@ module API
items
.
search
(
text
)
end
def
order_options_with_tie_breaker
order_options
=
{
params
[
:order_by
]
=>
params
[
:sort
]
}
order_options
[
'id'
]
||=
'desc'
order_options
end
# error helpers
def
forbidden!
(
reason
=
nil
)
...
...
@@ -397,12 +403,6 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
def
order_options_with_tie_breaker
order_options
=
{
params
[
:order_by
]
=>
params
[
:sort
]
}
order_options
[
'id'
]
||=
'desc'
order_options
end
def
project_finder_params
finder_params
=
{
without_deleted:
true
}
finder_params
[
:owned
]
=
true
if
params
[
:owned
].
present?
...
...
spec/support/shared_examples/requests/api/notes.rb
View file @
eccfab44
...
...
@@ -8,13 +8,45 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
create_list
(
:note
,
3
,
params
)
end
it
'sorts by created_at in descending order by default'
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
noteable_type
}
/
#{
noteable
[
id_name
]
}
/notes"
,
user
)
context
'without sort params'
do
it
'sorts by created_at in descending order by default'
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
noteable_type
}
/
#{
noteable
[
id_name
]
}
/notes"
,
user
)
response_dates
=
json_response
.
map
{
|
note
|
note
[
'created_at'
]
}
response_dates
=
json_response
.
map
{
|
note
|
note
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
context
'2 notes with equal created_at'
do
before
do
@first_note
=
Note
.
first
params
=
{
noteable:
noteable
,
author:
user
}
params
[
:project
]
=
parent
if
parent
.
is_a?
(
Project
)
params
[
:created_at
]
=
@first_note
.
created_at
@note2
=
create
(
:note
,
params
)
end
it
'page breaks first page correctly'
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
noteable_type
}
/
#{
noteable
[
id_name
]
}
/notes?per_page=4"
,
user
)
response_ids
=
json_response
.
map
{
|
note
|
note
[
'id'
]
}
expect
(
response_ids
).
to
include
(
@note2
.
id
)
expect
(
response_ids
).
not_to
include
(
@first_note
.
id
)
end
it
'page breaks second page correctly'
do
get
api
(
"/
#{
parent_type
}
/
#{
parent
.
id
}
/
#{
noteable_type
}
/
#{
noteable
[
id_name
]
}
/notes?per_page=4&page=2"
,
user
)
response_ids
=
json_response
.
map
{
|
note
|
note
[
'id'
]
}
expect
(
response_ids
).
not_to
include
(
@note2
.
id
)
expect
(
response_ids
).
to
include
(
@first_note
.
id
)
end
end
end
it
'sorts by ascending order when requested'
do
...
...
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