summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/pg_class_spec.rb
blob: 83b50415a6ca47481ba49da2396e19440c6bd55b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::PgClass, type: :model do
  describe '#cardinality_estimate' do
    context 'when no information is available' do
      subject { described_class.new(reltuples: 0.0).cardinality_estimate }

      it 'returns nil for the estimate' do
        expect(subject).to be_nil
      end
    end

    context 'with reltuples available' do
      subject { described_class.new(reltuples: 42.0).cardinality_estimate }

      it 'returns the reltuples for the estimate' do
        expect(subject).to eq(42)
      end
    end
  end

  describe '.for_table' do
    let(:relname) { :projects }

    subject { described_class.for_table(relname) }

    it 'returns PgClass for this table' do
      expect(subject).to be_a(described_class)
    end

    it 'matches the relname' do
      expect(subject.relname).to eq(relname.to_s)
    end
  end
end