diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/initializers | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/initializers')
-rw-r--r-- | spec/initializers/00_connection_logger_spec.rb | 39 | ||||
-rw-r--r-- | spec/initializers/validate_database_config_spec.rb | 40 |
2 files changed, 47 insertions, 32 deletions
diff --git a/spec/initializers/00_connection_logger_spec.rb b/spec/initializers/00_connection_logger_spec.rb new file mode 100644 index 00000000000..8b288b463c4 --- /dev/null +++ b/spec/initializers/00_connection_logger_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ActiveRecord::ConnectionAdapters::PostgreSQLAdapter do # rubocop:disable RSpec/FilePath + before do + allow(PG).to receive(:connect) + end + + let(:conn_params) { PG::Connection.conndefaults_hash } + + context 'when warn_on_new_connection is enabled' do + before do + described_class.warn_on_new_connection = true + end + + it 'warns on new connection' do + expect(ActiveSupport::Deprecation) + .to receive(:warn).with(/Database connection should not be called during initializers/, anything) + + expect(PG).to receive(:connect).with(conn_params) + + described_class.new_client(conn_params) + end + end + + context 'when warn_on_new_connection is disabled' do + before do + described_class.warn_on_new_connection = false + end + + it 'does not warn on new connection' do + expect(ActiveSupport::Deprecation).not_to receive(:warn) + expect(PG).to receive(:connect).with(conn_params) + + described_class.new_client(conn_params) + end + end +end diff --git a/spec/initializers/validate_database_config_spec.rb b/spec/initializers/validate_database_config_spec.rb index 209d9691350..5f3f950a852 100644 --- a/spec/initializers/validate_database_config_spec.rb +++ b/spec/initializers/validate_database_config_spec.rb @@ -39,47 +39,23 @@ RSpec.describe 'validate database config' do end context 'when config/database.yml is valid' do - context 'uses legacy syntax' do - let(:database_yml) do - <<-EOS - production: + let(:database_yml) do + <<-EOS + production: + main: adapter: postgresql encoding: unicode database: gitlabhq_production username: git password: "secure password" host: localhost - EOS - end - - it 'validates configuration with a warning' do - expect(main_object).to receive(:warn).with /uses a deprecated syntax for/ - - expect { subject }.not_to raise_error - end - - it_behaves_like 'with SKIP_DATABASE_CONFIG_VALIDATION=true' + EOS end - context 'uses new syntax' do - let(:database_yml) do - <<-EOS - production: - main: - adapter: postgresql - encoding: unicode - database: gitlabhq_production - username: git - password: "secure password" - host: localhost - EOS - end + it 'validates configuration without errors and warnings' do + expect(main_object).not_to receive(:warn) - it 'validates configuration without errors and warnings' do - expect(main_object).not_to receive(:warn) - - expect { subject }.not_to raise_error - end + expect { subject }.not_to raise_error end end |