diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-25 15:18:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-25 15:18:56 +0300 |
commit | d2d913b606702ecefa01f03362602fde256e3f75 (patch) | |
tree | 07643306ee63f789188a9133823aac3c92c94dfb /spec/initializers | |
parent | af69e63b6655a450849a8fa2640ae6ce5a8db681 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/initializers')
-rw-r--r-- | spec/initializers/active_record_transaction_observer_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/initializers/active_record_transaction_observer_spec.rb b/spec/initializers/active_record_transaction_observer_spec.rb new file mode 100644 index 00000000000..a834037dce5 --- /dev/null +++ b/spec/initializers/active_record_transaction_observer_spec.rb @@ -0,0 +1,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 |