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'