Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions spec/chrono_model/adapter/migrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Loading