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
302c1f5f
Commit
302c1f5f
authored
Feb 07, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added specs for Keyset connenction using LOWER
in GraphQL
parent
f503bfec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
57 deletions
+93
-57
spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
.../lib/gitlab/graphql/connections/keyset/connection_spec.rb
+93
-57
No files found.
spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
View file @
302c1f5f
...
@@ -103,93 +103,119 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
...
@@ -103,93 +103,119 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end
end
end
end
context
'when multiple orders are defined'
do
shared_examples
'nodes are in ascending order'
do
let!
(
:project1
)
{
create
(
:project
,
last_repository_check_at:
10
.
days
.
ago
)
}
# Asc: project5 Desc: project3
let!
(
:project2
)
{
create
(
:project
,
last_repository_check_at:
nil
)
}
# Asc: project1 Desc: project1
let!
(
:project3
)
{
create
(
:project
,
last_repository_check_at:
5
.
days
.
ago
)
}
# Asc: project3 Desc: project5
let!
(
:project4
)
{
create
(
:project
,
last_repository_check_at:
nil
)
}
# Asc: project2 Desc: project2
let!
(
:project5
)
{
create
(
:project
,
last_repository_check_at:
20
.
days
.
ago
)
}
# Asc: project4 Desc: project4
context
'when ascending'
do
let
(
:nodes
)
do
Project
.
order
(
Arel
.
sql
(
'projects.last_repository_check_at IS NULL'
)).
order
(
last_repository_check_at: :asc
).
order
(
id: :asc
)
end
context
'when no cursor is passed'
do
context
'when no cursor is passed'
do
let
(
:arguments
)
{
{}
}
let
(
:arguments
)
{
{}
}
it
'returns projects in ascending order'
do
it
'returns projects in ascending order'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project5
,
project1
,
project3
,
project2
,
project4
]
)
expect
(
subject
.
sliced_nodes
).
to
eq
(
ascending_nodes
)
end
end
end
end
context
'when before cursor value is
NULL'
do
context
'when before cursor value is not
NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
)
}
}
let
(
:arguments
)
{
{
before:
encoded_cursor
(
ascending_nodes
[
2
]
)
}
}
it
'returns all projects before the cursor'
do
it
'returns all projects before the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project5
,
project1
,
project3
,
project2
]
)
expect
(
subject
.
sliced_nodes
).
to
eq
(
ascending_nodes
.
first
(
2
)
)
end
end
end
end
context
'when before
cursor value is not NULL'
do
context
'when after
cursor value is not NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project3
)
}
}
let
(
:arguments
)
{
{
after:
encoded_cursor
(
ascending_nodes
[
1
]
)
}
}
it
'returns all projects before
the cursor'
do
it
'returns all projects after
the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project5
,
project1
]
)
expect
(
subject
.
sliced_nodes
).
to
eq
(
ascending_nodes
.
last
(
3
)
)
end
end
end
end
context
'when after cursor value is NULL
'
do
context
'when before and after cursor
'
do
let
(
:arguments
)
{
{
after:
encoded_cursor
(
project2
)
}
}
let
(
:arguments
)
{
{
before:
encoded_cursor
(
ascending_nodes
.
last
),
after:
encoded_cursor
(
ascending_nodes
.
first
)
}
}
it
'returns all projects after the cursor'
do
it
'returns all projects after the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project4
])
expect
(
subject
.
sliced_nodes
).
to
eq
(
ascending_nodes
[
1
..
3
])
end
end
end
shared_examples
'nodes are in descending order'
do
context
'when no cursor is passed'
do
let
(
:arguments
)
{
{}
}
it
'only returns projects in descending order'
do
expect
(
subject
.
sliced_nodes
).
to
eq
(
descending_nodes
)
end
end
context
'when before cursor value is not NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
descending_nodes
[
2
])
}
}
it
'returns all projects before the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
(
descending_nodes
.
first
(
2
))
end
end
end
end
context
'when after cursor value is not NULL'
do
context
'when after cursor value is not NULL'
do
let
(
:arguments
)
{
{
after:
encoded_cursor
(
project1
)
}
}
let
(
:arguments
)
{
{
after:
encoded_cursor
(
descending_nodes
[
1
]
)
}
}
it
'returns all projects after the cursor'
do
it
'returns all projects after the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project3
,
project2
,
project4
]
)
expect
(
subject
.
sliced_nodes
).
to
eq
(
descending_nodes
.
last
(
3
)
)
end
end
end
end
context
'when before and after cursor'
do
context
'when before and after cursor'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
),
after:
encoded_cursor
(
project5
)
}
}
let
(
:arguments
)
{
{
before:
encoded_cursor
(
descending_nodes
.
last
),
after:
encoded_cursor
(
descending_nodes
.
first
)
}
}
it
'returns all projects after the cursor'
do
it
'returns all projects after the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project1
,
project3
,
project2
])
expect
(
subject
.
sliced_nodes
).
to
eq
(
descending_nodes
[
1
..
3
])
end
end
end
end
end
end
context
'when descending'
do
context
'when multiple orders with nil values are defined'
do
let!
(
:project1
)
{
create
(
:project
,
last_repository_check_at:
10
.
days
.
ago
)
}
# Asc: project5 Desc: project3
let!
(
:project2
)
{
create
(
:project
,
last_repository_check_at:
nil
)
}
# Asc: project1 Desc: project1
let!
(
:project3
)
{
create
(
:project
,
last_repository_check_at:
5
.
days
.
ago
)
}
# Asc: project3 Desc: project5
let!
(
:project4
)
{
create
(
:project
,
last_repository_check_at:
nil
)
}
# Asc: project2 Desc: project2
let!
(
:project5
)
{
create
(
:project
,
last_repository_check_at:
20
.
days
.
ago
)
}
# Asc: project4 Desc: project4
context
'when ascending'
do
let
(
:nodes
)
do
let
(
:nodes
)
do
Project
.
order
(
Arel
.
sql
(
'projects.last_repository_check_at IS NULL'
)).
order
(
last_repository_check_at: :
de
sc
).
order
(
id: :asc
)
Project
.
order
(
Arel
.
sql
(
'projects.last_repository_check_at IS NULL'
)).
order
(
last_repository_check_at: :
a
sc
).
order
(
id: :asc
)
end
end
let
(
:ascending_nodes
)
{
[
project5
,
project1
,
project3
,
project2
,
project4
]
}
context
'when no cursor is passed'
do
it_behaves_like
'nodes are in ascending order'
let
(
:arguments
)
{
{}
}
it
'only returns projects in descending order'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project3
,
project1
,
project5
,
project2
,
project4
])
end
end
context
'when before cursor value is NULL'
do
context
'when before cursor value is NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
)
}
}
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
)
}
}
it
'returns all projects before the cursor'
do
it
'returns all projects before the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project
3
,
project1
,
project5
,
project2
])
expect
(
subject
.
sliced_nodes
).
to
eq
([
project
5
,
project1
,
project3
,
project2
])
end
end
end
end
context
'when before cursor value is not NULL'
do
context
'when after cursor value is NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project5
)
}
}
let
(
:arguments
)
{
{
after:
encoded_cursor
(
project2
)
}
}
it
'returns all projects after the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project4
])
end
end
end
context
'when descending'
do
let
(
:nodes
)
do
Project
.
order
(
Arel
.
sql
(
'projects.last_repository_check_at IS NULL'
)).
order
(
last_repository_check_at: :desc
).
order
(
id: :asc
)
end
let
(
:descending_nodes
)
{
[
project3
,
project1
,
project5
,
project2
,
project4
]
}
it_behaves_like
'nodes are in descending order'
context
'when before cursor value is NULL'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
)
}
}
it
'returns all projects before the cursor'
do
it
'returns all projects before the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project3
,
project1
])
expect
(
subject
.
sliced_nodes
).
to
eq
([
project3
,
project1
,
project5
,
project2
])
end
end
end
end
...
@@ -200,22 +226,32 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
...
@@ -200,22 +226,32 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project4
])
expect
(
subject
.
sliced_nodes
).
to
eq
([
project4
])
end
end
end
end
context
'when after cursor value is not NULL'
do
let
(
:arguments
)
{
{
after:
encoded_cursor
(
project1
)
}
}
it
'returns all projects after the cursor'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project5
,
project2
,
project4
])
end
end
end
end
context
'when before and after cursor'
do
context
'when ordering uses LOWER'
do
let
(
:arguments
)
{
{
before:
encoded_cursor
(
project4
),
after:
encoded_cursor
(
project3
)
}
}
let!
(
:project1
)
{
create
(
:project
,
name:
'A'
)
}
# Asc: project1 Desc: project4
let!
(
:project2
)
{
create
(
:project
,
name:
'c'
)
}
# Asc: project5 Desc: project2
let!
(
:project3
)
{
create
(
:project
,
name:
'b'
)
}
# Asc: project3 Desc: project3
let!
(
:project4
)
{
create
(
:project
,
name:
'd'
)
}
# Asc: project2 Desc: project5
let!
(
:project5
)
{
create
(
:project
,
name:
'a'
)
}
# Asc: project4 Desc: project1
it
'returns all projects after the cursor'
do
context
'when ascending'
do
expect
(
subject
.
sliced_nodes
).
to
eq
([
project1
,
project5
,
project2
])
let
(
:nodes
)
do
Project
.
order
(
Arel
::
Table
.
new
(
:projects
)[
'name'
].
lower
.
asc
).
order
(
id: :asc
)
end
end
let
(
:ascending_nodes
)
{
[
project1
,
project5
,
project3
,
project2
,
project4
]
}
it_behaves_like
'nodes are in ascending order'
end
end
context
'when descending'
do
let
(
:nodes
)
do
Project
.
order
(
Arel
::
Table
.
new
(
:projects
)[
'name'
].
lower
.
desc
).
order
(
id: :desc
)
end
let
(
:descending_nodes
)
{
[
project4
,
project2
,
project3
,
project5
,
project1
]
}
it_behaves_like
'nodes are in descending order'
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