summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/pagination/keyset_spec.rb
blob: bde280c5fcace69e3f4d0df8647d06dcba728ddc (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
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Pagination::Keyset do
  describe '.available?' do
    subject { described_class }

    let(:request_context) { double("request context", page: page)}
    let(:page) { double("page", order_by: order_by) }

    shared_examples_for 'keyset pagination is available' do
      it 'returns true for Project' do
        expect(subject.available?(request_context, Project.all)).to be_truthy
      end

      it 'return false for other types of relations' do
        expect(subject.available?(request_context, User.all)).to be_falsey
      end
    end

    context 'with order-by id asc' do
      let(:order_by) { { id: :asc } }

      it_behaves_like 'keyset pagination is available'
    end

    context 'with order-by id desc' do
      let(:order_by) { { id: :desc } }

      it_behaves_like 'keyset pagination is available'
    end

    context 'with other order-by columns' do
      let(:order_by) { { created_at: :desc, id: :desc } }

      it 'returns false for Project' do
        expect(subject.available?(request_context, Project.all)).to be_falsey
      end

      it 'return false for other types of relations' do
        expect(subject.available?(request_context, User.all)).to be_falsey
      end
    end
  end
end