blob: a834037dce53eac88fb0b3edc4ba12d1d5e0d52d (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'ActiveRecord Transaction Observer', feature_category: :application_performance do
def load_initializer
load Rails.root.join('config/initializers/active_record_transaction_observer.rb')
end
context 'when DBMS is available' do
before do
allow_next_instance_of(ActiveRecord::Base.connection) do |connection| # rubocop:disable Database/MultipleDatabases
allow(connection).to receive(:active?).and_return(true)
end
end
it 'calls Gitlab::Database::Transaction::Observer' do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_return(true)
expect(Gitlab::Database::Transaction::Observer).to receive(:register!)
load_initializer
end
context 'when flipper table does not exist' do
before do
allow(Feature::FlipperFeature).to receive(:table_exists?).and_raise(ActiveRecord::NoDatabaseError)
end
it 'does not calls Gitlab::Database::Transaction::Observer' do
expect(Gitlab::Database::Transaction::Observer).not_to receive(:register!)
load_initializer
end
end
end
context 'when DBMS is not available' do
before do
allow(ActiveRecord::Base).to receive(:connection).and_raise(PG::ConnectionBad)
end
it 'does not calls Gitlab::Database::Transaction::Observer' do
expect(Gitlab::Database::Transaction::Observer).not_to receive(:register!)
load_initializer
end
end
end
|