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

28 lines
883 B
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
class BeforeAllAdapter # rubocop:disable Gitlab/NamespacedClass
2021-11-18 22:05:49 +05:30
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
def self.begin_transaction
2021-11-18 22:05:49 +05:30
self.all_connection_classes.each do |connection_class|
connection_class.connection.begin_transaction(joinable: false)
2021-10-27 15:23:28 +05:30
end
end
def self.rollback_transaction
2021-11-18 22:05:49 +05:30
self.all_connection_classes.each do |connection_class|
if connection_class.connection.open_transactions.zero?
2021-10-27 15:23:28 +05:30
warn "!!! before_all transaction has been already rollbacked and " \
"could work incorrectly"
next
end
2021-11-18 22:05:49 +05:30
connection_class.connection.rollback_transaction
2021-10-27 15:23:28 +05:30
end
end
end
TestProf::BeforeAll.adapter = ::BeforeAllAdapter