blob: 18bbc6c1dd3797440c8b1f9a3d15edf13fc02587 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Database::Migration do
describe '.[]' do
context 'version: 1.0' do
subject { described_class[1.0] }
it 'inherits from ActiveRecord::Migration[6.1]' do
expect(subject.superclass).to eq(ActiveRecord::Migration[6.1])
end
it 'includes migration helpers version 2' do
expect(subject.included_modules).to include(Gitlab::Database::MigrationHelpers::V2)
end
it 'includes LockRetriesConcern' do
expect(subject.included_modules).to include(Gitlab::Database::Migration::LockRetriesConcern)
end
end
context 'unknown version' do
it 'raises an error' do
expect { described_class[0] }.to raise_error(ArgumentError, /Unknown migration version/)
end
end
end
describe '.current_version' do
it 'includes current ActiveRecord migration class' do
# This breaks upon Rails upgrade. In that case, we'll add a new version in Gitlab::Database::Migration::MIGRATION_CLASSES,
# bump .current_version and leave existing migrations and already defined versions of Gitlab::Database::Migration
# untouched.
expect(described_class[described_class.current_version]).to be < ActiveRecord::Migration::Current
end
end
describe Gitlab::Database::Migration::LockRetriesConcern do
subject { class_def.new }
context 'when not explicitly called' do
let(:class_def) do
Class.new do
include Gitlab::Database::Migration::LockRetriesConcern
end
end
it 'does not disable lock retries by default' do
expect(subject.enable_lock_retries?).not_to be_truthy
end
end
context 'when explicitly disabled' do
let(:class_def) do
Class.new do
include Gitlab::Database::Migration::LockRetriesConcern
enable_lock_retries!
end
end
it 'does not disable lock retries by default' do
expect(subject.enable_lock_retries?).to be_truthy
end
end
end
end
|