diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-01 06:09:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-01 06:09:04 +0300 |
commit | d0356412dfc91d02585f0a177c65677dbe2944a3 (patch) | |
tree | 5a2ac806b6ea6113475bb2a759f6b15c186fb482 /spec/lib/gitlab/graphql | |
parent | 72817fd7c07d1b812623f8d5e27fc7bcecb4eed5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/graphql')
3 files changed, 91 insertions, 59 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 d943540fe1f..5e215be4dfb 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 @@ -4,10 +4,15 @@ require 'spec_helper' describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do describe '#build' do - let(:condition) { described_class.new(Issue.arel_table, %w(relative_position id), [1500, 500], ['>', '>'], before_or_after) } + let(:operators) { ['>', '>'] } + let(:before_or_after) { :after } + let(:condition) { described_class.new(arel_table, order_list, values, operators, before_or_after) } context 'when there is only one ordering field' do - let(:condition) { described_class.new(Issue.arel_table, ['id'], [500], ['>'], :after) } + let(:arel_table) { Issue.arel_table } + let(:order_list) { ['id'] } + let(:values) { [500] } + let(:operators) { ['>'] } it 'generates a single condition sql' do expected_sql = <<~SQL @@ -18,38 +23,52 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do end end - context 'when :after' do - let(:before_or_after) { :after } + context 'when ordering by a column attribute' do + let(:arel_table) { Issue.arel_table } + let(:order_list) { %w(relative_position id) } + let(:values) { [1500, 500] } - it 'generates :after sql' do - expected_sql = <<~SQL - ("issues"."relative_position" > 1500) - OR ( - "issues"."relative_position" = 1500 - AND - "issues"."id" > 500 - ) - OR ("issues"."relative_position" IS NULL) - SQL + shared_examples ':after condition' do + it 'generates :after sql' do + expected_sql = <<~SQL + ("issues"."relative_position" > 1500) + OR ( + "issues"."relative_position" = 1500 + AND + "issues"."id" > 500 + ) + OR ("issues"."relative_position" IS NULL) + SQL - expect(condition.build.squish).to eq expected_sql.squish + expect(condition.build.squish).to eq expected_sql.squish + end end - end - context 'when :before' do - let(:before_or_after) { :before } + context 'when :after' do + it_behaves_like ':after condition' + end - it 'generates :before sql' do - expected_sql = <<~SQL - ("issues"."relative_position" > 1500) - OR ( - "issues"."relative_position" = 1500 - AND - "issues"."id" > 500 - ) - SQL + context 'when :before' do + let(:before_or_after) { :before } - expect(condition.build.squish).to eq expected_sql.squish + it 'generates :before sql' do + expected_sql = <<~SQL + ("issues"."relative_position" > 1500) + OR ( + "issues"."relative_position" = 1500 + AND + "issues"."id" > 500 + ) + SQL + + expect(condition.build.squish).to eq expected_sql.squish + end + end + + context 'when :foo' do + let(:before_or_after) { :foo } + + it_behaves_like ':after condition' 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 7fce94adb81..1049890a079 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 @@ -4,38 +4,54 @@ require 'spec_helper' describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do describe '#build' do - let(:condition) { described_class.new(Issue.arel_table, %w(relative_position id), [nil, 500], [nil, '>'], before_or_after) } - - context 'when :after' do - let(:before_or_after) { :after } - - it 'generates sql' do - expected_sql = <<~SQL - ( - "issues"."relative_position" IS NULL - AND - "issues"."id" > 500 - ) - SQL + let(:values) { [nil, 500] } + let(:operators) { [nil, '>'] } + let(:before_or_after) { :after } + let(:condition) { described_class.new(arel_table, order_list, values, operators, before_or_after) } + + context 'when ordering by a column attribute' do + let(:arel_table) { Issue.arel_table } + let(:order_list) { %w(relative_position id) } + + shared_examples ':after condition' do + it 'generates sql' do + expected_sql = <<~SQL + ( + "issues"."relative_position" IS NULL + AND + "issues"."id" > 500 + ) + SQL + + expect(condition.build.squish).to eq expected_sql.squish + end + end - expect(condition.build.squish).to eq expected_sql.squish + context 'when :after' do + it_behaves_like ':after condition' end - end - context 'when :before' do - let(:before_or_after) { :before } + context 'when :before' do + let(:before_or_after) { :before } + + it 'generates :before sql' do + expected_sql = <<~SQL + ( + "issues"."relative_position" IS NULL + AND + "issues"."id" > 500 + ) + OR ("issues"."relative_position" IS NOT NULL) + SQL + + expect(condition.build.squish).to eq expected_sql.squish + end + end - it 'generates :before sql' do - expected_sql = <<~SQL - ( - "issues"."relative_position" IS NULL - AND - "issues"."id" > 500 - ) - OR ("issues"."relative_position" IS NOT NULL) - SQL + context 'when :foo' do + let(:before_or_after) { :foo } - expect(condition.build.squish).to eq expected_sql.squish + it_behaves_like ':after condition' end end end 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 59e153d9e07..7ebf5da264d 100644 --- a/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb +++ b/spec/lib/gitlab/graphql/connections/keyset/query_builder_spec.rb @@ -13,6 +13,7 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do describe '#conditions' do let(:relation) { Issue.order(relative_position: :desc).order(:id) } let(:order_list) { Gitlab::Graphql::Connections::Keyset::OrderInfo.build_order_list(relation) } + let(:arel_table) { Issue.arel_table } let(:builder) { described_class.new(arel_table, order_list, decoded_cursor, before_or_after) } let(:before_or_after) { :after } @@ -101,8 +102,4 @@ describe Gitlab::Graphql::Connections::Keyset::QueryBuilder do end end end - - def arel_table - Issue.arel_table - end end |