debian-mirror-gitlab/spec/models/concerns/ci/partitionable_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.1 KiB
Ruby
Raw Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::Partitionable do
2023-01-13 00:05:48 +05:30
let(:ci_model) { Class.new(Ci::ApplicationRecord) }
2022-11-25 23:54:43 +05:30
2023-01-13 00:05:48 +05:30
describe 'partitionable models inclusion' do
2022-11-25 23:54:43 +05:30
subject { ci_model.include(described_class) }
it 'raises an exception' do
expect { subject }
.to raise_error(/must be included in PARTITIONABLE_MODELS/)
end
context 'when is included in the models list' do
before do
stub_const("#{described_class}::Testing::PARTITIONABLE_MODELS", [ci_model.name])
end
it 'does not raise exceptions' do
expect { subject }.not_to raise_error
end
end
end
2023-01-13 00:05:48 +05:30
context 'with through options' do
before do
allow(ActiveSupport::DescendantsTracker).to receive(:store_inherited)
stub_const("#{described_class}::Testing::PARTITIONABLE_MODELS", [ci_model.name])
ci_model.include(described_class)
ci_model.partitionable scope: ->(r) { 1 },
2023-06-20 00:43:36 +05:30
through: { table: :_test_table_name, flag: :some_flag }
2023-01-13 00:05:48 +05:30
end
it { expect(ci_model.routing_table_name).to eq(:_test_table_name) }
it { expect(ci_model.routing_table_name_flag).to eq(:some_flag) }
it { expect(ci_model.ancestors).to include(described_class::Switch) }
end
2023-03-04 22:38:38 +05:30
context 'with partitioned options' do
before do
stub_const("#{described_class}::Testing::PARTITIONABLE_MODELS", [ci_model.name])
ci_model.include(described_class)
ci_model.partitionable scope: ->(r) { 1 }, partitioned: partitioned
end
context 'when partitioned is true' do
let(:partitioned) { true }
2023-05-27 22:25:52 +05:30
it { expect(ci_model.ancestors).to include(PartitionedTable) }
it { expect(ci_model.partitioning_strategy).to be_a(Gitlab::Database::Partitioning::CiSlidingListStrategy) }
it { expect(ci_model.partitioning_strategy.partitioning_key).to eq(:partition_id) }
2023-03-04 22:38:38 +05:30
end
context 'when partitioned is false' do
let(:partitioned) { false }
2023-05-27 22:25:52 +05:30
it { expect(ci_model.ancestors).not_to include(PartitionedTable) }
it { expect(ci_model).not_to respond_to(:partitioning_strategy) }
2023-03-04 22:38:38 +05:30
end
end
2022-11-25 23:54:43 +05:30
end