From b16656a5b2d826d297b746a5140fe0c44fc9e2d1 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Mon, 26 May 2025 14:24:23 +0200 Subject: [PATCH] Add failing spec for #318 and #173 --- spec/chrono_model/adapter/migrations_spec.rb | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/spec/chrono_model/adapter/migrations_spec.rb b/spec/chrono_model/adapter/migrations_spec.rb index 42d10b8d..b03708fb 100644 --- a/spec/chrono_model/adapter/migrations_spec.rb +++ b/spec/chrono_model/adapter/migrations_spec.rb @@ -40,7 +40,25 @@ describe '.create_table' do context 'with temporal tables' do include_context 'with temporal tables' + it_behaves_like 'temporal table' + + context 'when columns have an index' do + let(:columns) do + native = [] + + def native.to_proc + proc { |t| + t.string :bar, index: true + } + end + + native + end + + it { is_expected.to have_temporal_index 'index_test_table_on_bar', %w[bar] } + it { is_expected.to have_history_index 'index_test_table_on_bar', %w[bar] } + end end context 'with plain tables' do @@ -235,6 +253,42 @@ end end + describe '.add_reference' do + context 'with temporal tables' do + include_context 'with temporal tables' + + before do + adapter.add_reference table, :foo + end + + it { is_expected.to have_columns([%w[foo_id bigint]]) } + it { is_expected.to have_temporal_columns([%w[foo_id bigint]]) } + it { is_expected.to have_history_columns([%w[foo_id bigint]]) } + + it { is_expected.to have_temporal_index 'index_test_table_on_foo_id', %w[foo_id] } + it { is_expected.to have_history_index 'index_test_table_on_foo_id', %w[foo_id] } + end + end + + describe '.references' do + context 'with temporal tables' do + include_context 'with temporal tables' + + before do + adapter.create_table table, force: true, temporal: true do |t| + t.references :foo + end + end + + it { is_expected.to have_columns([%w[foo_id bigint]]) } + it { is_expected.to have_temporal_columns([%w[foo_id bigint]]) } + it { is_expected.to have_history_columns([%w[foo_id bigint]]) } + + it { is_expected.to have_temporal_index 'index_test_table_on_foo_id', %w[foo_id] } + it { is_expected.to have_history_index 'index_test_table_on_foo_id', %w[foo_id] } + end + end + describe '.add_index' do context 'with temporal tables' do include_context 'with temporal tables'