File: database_config_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (39 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Database config initializer', :reestablished_active_record_base do
  subject do
    load Rails.root.join('config/initializers/database_config.rb')
  end

  shared_examples 'does not change connection attributes' do
    it 'retains the correct database name for connection' do
      previous_db_name = database_base_model.connection.pool.db_config.name

      subject

      expect(database_base_model.connection.pool.db_config.name).to eq(previous_db_name)
    end

    it 'does not overwrite custom pool settings' do
      expect { subject }.not_to change { database_base_model.connection_db_config.pool }
    end
  end

  context 'when main database connection' do
    let(:database_base_model) { Gitlab::Database.database_base_models[:main] }

    it_behaves_like 'does not change connection attributes'
  end

  context 'when ci database connection' do
    before do
      skip_if_multiple_databases_not_setup(:ci)
    end

    let(:database_base_model) { Gitlab::Database.database_base_models[:ci] }

    it_behaves_like 'does not change connection attributes'
  end
end