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

order_by_column_data_spec.rb « in_operator_optimization « keyset « pagination « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4869f490819a1b22bb974209d6b92464e88f6a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Pagination::Keyset::InOperatorOptimization::OrderByColumnData do
  let(:arel_table) { Issue.arel_table }

  let(:column) do
    Gitlab::Pagination::Keyset::ColumnOrderDefinition.new(
      attribute_name: :id,
      column_expression: arel_table[:id],
      order_expression: arel_table[:id].desc
    )
  end

  subject(:column_data) { described_class.new(column, 'column_alias', arel_table) }

  describe '#arel_column' do
    it 'delegates to column_expression' do
      expect(column_data.arel_column).to eq(column.column_expression)
    end
  end

  describe '#column_for_projection' do
    it 'returns the expression with AS using the original column name' do
      expect(column_data.column_for_projection.to_sql).to eq('"issues"."id" AS id')
    end
  end

  describe '#projection' do
    it 'returns the expression with AS using the specified column lias' do
      expect(column_data.projection.to_sql).to eq('"issues"."id" AS column_alias')
    end
  end
end