summaryrefslogtreecommitdiff
path: root/spec/models/concerns/partitioned_table_spec.rb
blob: 3343b273ba28d219ecb872b4a93e5808a91b3ea1 (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 PartitionedTable do
  describe '.partitioned_by' do
    subject { my_class.partitioned_by(key, strategy: :monthly) }

    let(:key) { :foo }

    let(:my_class) do
      Class.new do
        include PartitionedTable
      end
    end

    it 'assigns the MonthlyStrategy as the partitioning strategy' do
      subject

      expect(my_class.partitioning_strategy).to be_a(Gitlab::Database::Partitioning::MonthlyStrategy)
    end

    it 'passes the partitioning key to the strategy instance' do
      subject

      expect(my_class.partitioning_strategy.partitioning_key).to eq(key)
    end

    it 'registers itself with the PartitionCreator' do
      expect(Gitlab::Database::Partitioning::PartitionCreator).to receive(:register).with(my_class)

      subject
    end
  end
end