blob: 5d44dac8eb781f786b5f5668432731784673cd05 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MigrationsHelpers do
let(:helper_class) do
Class.new.tap do |klass|
klass.include described_class
allow(klass).to receive(:metadata).and_return(metadata)
end
end
let(:metadata) { {} }
let(:helper) { helper_class.new }
describe '#active_record_base' do
it 'returns the main base model' do
expect(helper.active_record_base).to eq(ActiveRecord::Base)
end
context 'ci database configured' do
before do
skip_if_multiple_databases_not_setup(:ci)
end
it 'returns the CI base model' do
expect(helper.active_record_base(database: :ci)).to eq(Ci::ApplicationRecord)
end
end
context 'ci database not configured' do
before do
skip_if_multiple_databases_are_setup(:ci)
end
it 'returns the main base model' do
expect(helper.active_record_base(database: :ci)).to eq(ActiveRecord::Base)
end
end
it 'raises ArgumentError for bad database argument' do
expect { helper.active_record_base(database: :non_existent) }.to raise_error(ArgumentError)
end
end
describe '#table' do
it 'creates a class based on main base model' do
klass = helper.table(:projects)
expect(klass.connection_specification_name).to eq('ActiveRecord::Base')
end
context 'ci database configured' do
before do
skip_if_multiple_databases_not_setup(:ci)
end
it 'create a class based on the CI base model' do
klass = helper.table(:ci_builds, database: :ci)
expect(klass.connection_specification_name).to eq('Ci::ApplicationRecord')
end
end
context 'ci database not configured' do
before do
skip_if_multiple_databases_are_setup(:ci)
end
it 'creates a class based on main base model' do
klass = helper.table(:ci_builds, database: :ci)
expect(klass.connection_specification_name).to eq('ActiveRecord::Base')
end
end
end
end
|