Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 18:08:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 18:08:44 +0300
commitbcc77054ee9aefd1e332e04a4189390fd5a3112e (patch)
treee6e1908c310e4733038794e932196cae0d66ba9a /spec/lib/gitlab/graphql
parent05b5c609cb8c260b10c2eb1b92b711dc82d32c3f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/graphql')
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb150
1 files changed, 93 insertions, 57 deletions
diff --git a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
index f617e8b3ce7..c193ab2b50f 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
@@ -103,7 +103,75 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end
end
- context 'when multiple orders are defined' do
+ shared_examples 'nodes are in ascending order' do
+ context 'when no cursor is passed' do
+ let(:arguments) { {} }
+
+ it 'returns projects in ascending order' do
+ expect(subject.sliced_nodes).to eq(ascending_nodes)
+ end
+ end
+
+ context 'when before cursor value is not NULL' do
+ let(:arguments) { { before: encoded_cursor(ascending_nodes[2]) } }
+
+ it 'returns all projects before the cursor' do
+ expect(subject.sliced_nodes).to eq(ascending_nodes.first(2))
+ end
+ end
+
+ context 'when after cursor value is not NULL' do
+ let(:arguments) { { after: encoded_cursor(ascending_nodes[1]) } }
+
+ it 'returns all projects after the cursor' do
+ expect(subject.sliced_nodes).to eq(ascending_nodes.last(3))
+ end
+ end
+
+ context 'when before and after cursor' do
+ let(:arguments) { { before: encoded_cursor(ascending_nodes.last), after: encoded_cursor(ascending_nodes.first) } }
+
+ it 'returns all projects after the cursor' do
+ 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
+
+ context 'when after cursor value is not NULL' do
+ let(:arguments) { { after: encoded_cursor(descending_nodes[1]) } }
+
+ it 'returns all projects after the cursor' do
+ expect(subject.sliced_nodes).to eq(descending_nodes.last(3))
+ end
+ end
+
+ context 'when before and after cursor' do
+ let(:arguments) { { before: encoded_cursor(descending_nodes.last), after: encoded_cursor(descending_nodes.first) } }
+
+ it 'returns all projects after the cursor' do
+ expect(subject.sliced_nodes).to eq(descending_nodes[1..3])
+ end
+ end
+ end
+
+ 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
@@ -114,14 +182,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection 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
+ let(:ascending_nodes) { [project5, project1, project3, project2, project4] }
- context 'when no cursor is passed' do
- let(:arguments) { {} }
-
- it 'returns projects in ascending order' do
- expect(subject.sliced_nodes).to eq([project5, project1, project3, project2, project4])
- end
- end
+ it_behaves_like 'nodes are in ascending order'
context 'when before cursor value is NULL' do
let(:arguments) { { before: encoded_cursor(project4) } }
@@ -131,14 +194,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end
end
- context 'when before cursor value is not NULL' do
- let(:arguments) { { before: encoded_cursor(project3) } }
-
- it 'returns all projects before the cursor' do
- expect(subject.sliced_nodes).to eq([project5, project1])
- end
- end
-
context 'when after cursor value is NULL' do
let(:arguments) { { after: encoded_cursor(project2) } }
@@ -146,36 +201,15 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
expect(subject.sliced_nodes).to eq([project4])
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([project3, project2, project4])
- end
- end
-
- context 'when before and after cursor' do
- let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project5) } }
-
- it 'returns all projects after the cursor' do
- expect(subject.sliced_nodes).to eq([project1, project3, project2])
- 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] }
- context 'when no cursor is passed' do
- let(:arguments) { {} }
-
- it 'only returns projects in descending order' do
- expect(subject.sliced_nodes).to eq([project3, project1, project5, project2, project4])
- end
- end
+ it_behaves_like 'nodes are in descending order'
context 'when before cursor value is NULL' do
let(:arguments) { { before: encoded_cursor(project4) } }
@@ -185,14 +219,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end
end
- context 'when before cursor value is not NULL' do
- let(:arguments) { { before: encoded_cursor(project5) } }
-
- it 'returns all projects before the cursor' do
- expect(subject.sliced_nodes).to eq([project3, project1])
- end
- end
-
context 'when after cursor value is NULL' do
let(:arguments) { { after: encoded_cursor(project2) } }
@@ -200,22 +226,32 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
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) } }
+ context 'when ordering uses LOWER' do
+ 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
- expect(subject.sliced_nodes).to eq([project5, project2, project4])
- end
+ context 'when ascending' do
+ let(:nodes) do
+ Project.order(Arel::Table.new(:projects)['name'].lower.asc).order(id: :asc)
end
+ let(:ascending_nodes) { [project1, project5, project3, project2, project4] }
- context 'when before and after cursor' do
- let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project3) } }
+ it_behaves_like 'nodes are in ascending order'
+ end
- it 'returns all projects after the cursor' do
- expect(subject.sliced_nodes).to eq([project1, project5, project2])
- 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