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
77a171a4
Commit
77a171a4
authored
Nov 05, 2019
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactor of OrderInfo
parent
2c66d576
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
lib/gitlab/graphql/connections/keyset/order_info.rb
lib/gitlab/graphql/connections/keyset/order_info.rb
+19
-10
spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb
.../lib/gitlab/graphql/connections/keyset/order_info_spec.rb
+2
-2
No files found.
lib/gitlab/graphql/connections/keyset/order_info.rb
View file @
77a171a4
...
...
@@ -9,14 +9,7 @@ module Gitlab
def
initialize
(
order_value
)
if
order_value
.
is_a?
(
String
)
tokens
=
order_value
.
downcase
.
split
(
' '
)
unless
tokens
[
-
2
..-
1
]
==
%w(nulls last)
&&
tokens
.
count
==
4
raise
ArgumentError
.
new
(
'Incorrect format for NULLS LAST'
)
end
@attribute_name
=
tokens
.
first
@sort_direction
=
tokens
[
1
]
==
'asc'
?
:asc
:
:desc
@attribute_name
,
@sort_direction
=
extract_nulls_last_order
(
order_value
)
else
@attribute_name
=
order_value
.
expr
.
name
@sort_direction
=
order_value
.
direction
...
...
@@ -35,8 +28,7 @@ module Gitlab
# Only allow specific node types
def
self
.
build_order_list
(
relation
)
order_list
=
relation
.
order_values
.
select
do
|
value
|
value
.
is_a?
(
Arel
::
Nodes
::
Ascending
)
||
value
.
is_a?
(
Arel
::
Nodes
::
Descending
)
||
(
value
.
is_a?
(
String
)
&&
value
.
downcase
.
end_with?
(
'nulls last'
))
supported_order_value?
(
value
)
end
order_list
.
map
{
|
info
|
OrderInfo
.
new
(
info
)
}
...
...
@@ -62,6 +54,23 @@ module Gitlab
raise
ArgumentError
.
new
(
"Last ordering field must be the primary key, `
#{
relation
.
primary_key
}
`"
)
end
end
def
self
.
supported_order_value?
(
order_value
)
return
true
if
order_value
.
is_a?
(
Arel
::
Nodes
::
Ascending
)
||
order_value
.
is_a?
(
Arel
::
Nodes
::
Descending
)
return
false
unless
order_value
.
is_a?
(
String
)
tokens
=
order_value
.
downcase
.
split
tokens
.
last
(
2
)
==
%w(nulls last)
&&
tokens
.
count
==
4
end
private
def
extract_nulls_last_order
(
order_value
)
tokens
=
order_value
.
downcase
.
split
[
tokens
.
first
,
(
tokens
[
1
]
==
'asc'
?
:asc
:
:desc
)]
end
end
end
end
...
...
spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb
View file @
77a171a4
...
...
@@ -33,8 +33,8 @@ describe Gitlab::Graphql::Connections::Keyset::OrderInfo do
context
'when order contains invalid formatted NULLS LAST '
do
let
(
:relation
)
{
Project
.
order
(
Arel
.
sql
(
'projects.updated_at created_at Asc Nulls Last'
)).
order
(
:id
)
}
it
'
raises an erro
r'
do
expect
{
order_list
}.
to
raise_error
(
ArgumentError
,
'Incorrect format for NULLS LAST'
)
it
'
ignores the SQL orde
r'
do
expect
(
order_list
.
count
).
to
eq
1
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