debian-mirror-gitlab/spec/support/before_all_adapter.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.2 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
2023-03-04 22:38:38 +05:30
module TestProfBeforeAllAdapter
module MultipleDatabaseAdapter
def self.all_connection_classes
@all_connection_classes ||= [ActiveRecord::Base] + ActiveRecord::Base.descendants.select(&:connection_class?) # rubocop: disable Database/MultipleDatabases
2021-10-27 15:23:28 +05:30
end
2023-03-04 22:38:38 +05:30
def self.begin_transaction
self.all_connection_classes.each do |connection_class|
connection_class.connection.begin_transaction(joinable: false)
2021-10-27 15:23:28 +05:30
end
2023-03-04 22:38:38 +05:30
end
2021-10-27 15:23:28 +05:30
2023-03-04 22:38:38 +05:30
def self.rollback_transaction
self.all_connection_classes.each do |connection_class|
if connection_class.connection.open_transactions.zero?
warn "!!! before_all transaction has been already rollbacked and " \
"could work incorrectly"
next
end
connection_class.connection.rollback_transaction
end
2021-10-27 15:23:28 +05:30
end
end
2023-03-04 22:38:38 +05:30
# This class is required so we can disable transactions on migration specs
module NoTransactionAdapter
def self.begin_transaction; end
def self.rollback_transaction; end
end
def self.default_adapter
MultipleDatabaseAdapter
end
def self.no_transaction_adapter
NoTransactionAdapter
end
2021-10-27 15:23:28 +05:30
end
2023-03-04 22:38:38 +05:30
TestProf::BeforeAll.adapter = ::TestProfBeforeAllAdapter.default_adapter