2021-08-05 08:09:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BeforeAllAdapter # rubocop:disable Gitlab/NamespacedClass
|
2021-09-20 17:11:31 -04:00
|
|
|
def self.all_connection_classes
|
|
|
|
@all_connection_classes ||= [ActiveRecord::Base] + ActiveRecord::Base.descendants.select(&:connection_class?) # rubocop: disable Database/MultipleDatabases
|
2021-08-05 08:09:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.begin_transaction
|
2021-09-20 17:11:31 -04:00
|
|
|
self.all_connection_classes.each do |connection_class|
|
|
|
|
connection_class.connection.begin_transaction(joinable: false)
|
2021-08-05 08:09:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.rollback_transaction
|
2021-09-20 17:11:31 -04:00
|
|
|
self.all_connection_classes.each do |connection_class|
|
|
|
|
if connection_class.connection.open_transactions.zero?
|
2021-08-05 08:09:57 -04:00
|
|
|
warn "!!! before_all transaction has been already rollbacked and " \
|
|
|
|
"could work incorrectly"
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2021-09-20 17:11:31 -04:00
|
|
|
connection_class.connection.rollback_transaction
|
2021-08-05 08:09:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
TestProf::BeforeAll.adapter = ::BeforeAllAdapter
|