Commit 04ac2ea4 authored by Brett Walker's avatar Brett Walker

Set default before_or_after for keyset conditions

and add relevant specs
parent db2c101c
......@@ -8,6 +8,8 @@ module Gitlab
class BaseCondition
def initialize(arel_table, order_list, values, operators, before_or_after)
@arel_table, @order_list, @values, @operators, @before_or_after = arel_table, order_list, values, operators, before_or_after
@before_or_after = :after unless [:after, :before].include?(@before_or_after)
end
def build
......
......@@ -28,7 +28,7 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
let(:order_list) { %w(relative_position id) }
let(:values) { [1500, 500] }
context 'when :after' do
shared_examples ':after condition' do
it 'generates :after sql' do
expected_sql = <<~SQL
("issues"."relative_position" > 1500)
......@@ -44,6 +44,10 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
end
end
context 'when :after' do
it_behaves_like ':after condition'
end
context 'when :before' do
let(:before_or_after) { :before }
......@@ -60,6 +64,12 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NotNullCondition do
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
end
......@@ -13,20 +13,24 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do
let(:arel_table) { Issue.arel_table }
let(:order_list) { %w(relative_position id) }
context 'when :after' do
shared_examples ':after condition' do
it 'generates sql' do
expected_sql = <<~SQL
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
(
"issues"."relative_position" IS NULL
AND
"issues"."id" > 500
)
SQL
expect(condition.build.squish).to eq expected_sql.squish
end
end
context 'when :after' do
it_behaves_like ':after condition'
end
context 'when :before' do
let(:before_or_after) { :before }
......@@ -43,6 +47,12 @@ describe Gitlab::Graphql::Connections::Keyset::Conditions::NullCondition do
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
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment