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-07 15:09:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 15:09:13 +0300
commit211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7 (patch)
tree0ad37172721a39b0d57240bb1b4e70f200a0d93e /spec/lib/gitlab/graphql
parent456a7247f9e88fc2518b69a1a00e905c6db6d775 (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/conditions/not_null_condition_spec.rb44
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb39
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb14
-rw-r--r--spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb30
4 files changed, 124 insertions, 3 deletions
diff --git a/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
index 5e215be4dfb..26fc5344871 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/conditions/not_null_condition_spec.rb
@@ -10,7 +10,7 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
context 'when there is only one ordering field' do
let(:arel_table) { Issue.arel_table }
- let(:order_list) { ['id'] }
+ let(:order_list) { [double(named_function: nil, attribute_name: 'id')] }
let(:values) { [500] }
let(:operators) { ['>'] }
@@ -25,7 +25,7 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
context 'when ordering by a column attribute' do
let(:arel_table) { Issue.arel_table }
- let(:order_list) { %w(relative_position id) }
+ let(:order_list) { [double(named_function: nil, attribute_name: 'relative_position'), double(named_function: nil, attribute_name: 'id')] }
let(:values) { [1500, 500] }
shared_examples ':after condition' do
@@ -71,5 +71,45 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
it_behaves_like ':after condition'
end
end
+
+ context 'when ordering by LOWER' do
+ let(:arel_table) { Project.arel_table }
+ let(:relation) { Project.order(arel_table['name'].lower.asc).order(:id) }
+ let(:order_list) { Gitlab::Graphql::Connections::Keyset::OrderInfo.build_order_list(relation) }
+ let(:values) { ['Test', 500] }
+
+ context 'when :after' do
+ it 'generates :after sql' do
+ expected_sql = <<~SQL
+ (LOWER("projects"."name") > 'test')
+ OR (
+ LOWER("projects"."name") = 'test'
+ AND
+ "projects"."id" > 500
+ )
+ OR (LOWER("projects"."name") IS NULL)
+ SQL
+
+ expect(condition.build.squish).to eq expected_sql.squish
+ end
+ end
+
+ context 'when :before' do
+ let(:before_or_after) { :before }
+
+ it 'generates :before sql' do
+ expected_sql = <<~SQL
+ (LOWER("projects"."name") > 'test')
+ OR (
+ LOWER("projects"."name") = 'test'
+ AND
+ "projects"."id" > 500
+ )
+ SQL
+
+ expect(condition.build.squish).to eq expected_sql.squish
+ end
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
index 1049890a079..be0a21b2438 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/conditions/null_condition_spec.rb
@@ -11,7 +11,7 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do
context 'when ordering by a column attribute' do
let(:arel_table) { Issue.arel_table }
- let(:order_list) { %w(relative_position id) }
+ let(:order_list) { [double(named_function: nil, attribute_name: 'relative_position'), double(named_function: nil, attribute_name: 'id')] }
shared_examples ':after condition' do
it 'generates sql' do
@@ -54,5 +54,42 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do
it_behaves_like ':after condition'
end
end
+
+ context 'when ordering by LOWER' do
+ let(:arel_table) { Project.arel_table }
+ let(:relation) { Project.order(arel_table['name'].lower.asc).order(:id) }
+ let(:order_list) { Gitlab::Graphql::Connections::Keyset::OrderInfo.build_order_list(relation) }
+
+ context 'when :after' do
+ it 'generates sql' do
+ expected_sql = <<~SQL
+ (
+ LOWER("projects"."name") IS NULL
+ AND
+ "projects"."id" > 500
+ )
+ SQL
+
+ expect(condition.build.squish).to eq expected_sql.squish
+ end
+ end
+
+ context 'when :before' do
+ let(:before_or_after) { :before }
+
+ it 'generates :before sql' do
+ expected_sql = <<~SQL
+ (
+ LOWER("projects"."name") IS NULL
+ AND
+ "projects"."id" > 500
+ )
+ OR (LOWER("projects"."name") IS NOT NULL)
+ SQL
+
+ expect(condition.build.squish).to eq expected_sql.squish
+ end
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb
index 17ddcaefeeb..eb823fc0122 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/order_info_spec.rb
@@ -37,6 +37,20 @@ describe Gitlab::Graphql::Connections::Keyset::OrderInfo do
expect(order_list.count).to eq 1
end
end
+
+ context 'when order contains LOWER' do
+ let(:relation) { Project.order(Arel::Table.new(:projects)['name'].lower.asc).order(:id) }
+
+ it 'does not ignore the SQL order' do
+ expect(order_list.count).to eq 2
+ expect(order_list.first.attribute_name).to eq 'name'
+ expect(order_list.first.named_function).to be_kind_of(Arel::Nodes::NamedFunction)
+ expect(order_list.first.named_function.to_sql).to eq 'LOWER("projects"."name")'
+ expect(order_list.first.operator_for(:after)).to eq '>'
+ expect(order_list.last.attribute_name).to eq 'id'
+ expect(order_list.last.operator_for(:after)).to eq '>'
+ end
+ end
end
describe '#validate_ordering' do
diff --git a/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
index 7ebf5da264d..b46ce4bf023 100644
--- a/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
+++ b/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb
@@ -101,5 +101,35 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do
end
end
end
+
+ context 'when sorting using LOWER' do
+ let(:relation) { Project.order(Arel::Table.new(:projects)['name'].lower.asc).order(:id) }
+ let(:arel_table) { Project.arel_table }
+ let(:decoded_cursor) { { 'name' => 'Test', 'id' => 100 } }
+
+ context 'when no values are nil' do
+ context 'when :after' do
+ it 'generates the correct condition' do
+ conditions = builder.conditions
+
+ expect(conditions).to include '(LOWER("projects"."name") > \'test\')'
+ expect(conditions).to include '"projects"."id" > 100'
+ expect(conditions).to include 'OR (LOWER("projects"."name") IS NULL)'
+ end
+ end
+
+ context 'when :before' do
+ let(:before_or_after) { :before }
+
+ it 'generates the correct condition' do
+ conditions = builder.conditions
+
+ expect(conditions).to include '(LOWER("projects"."name") < \'test\')'
+ expect(conditions).to include '"projects"."id" < 100'
+ expect(conditions).to include 'LOWER("projects"."name") = \'test\''
+ end
+ end
+ end
+ end
end
end