Sha256: f5a6178f7754cb00b0c51eba52b803379a6e90940152b8f4be8e0a47e5ddda65
Contents?: true
Size: 1016 Bytes
Versions: 8
Compression:
Stored size: 1016 Bytes
Contents
require 'rspec/core' module Rspec module Rails module TransactionalDatabaseSupport def active_record_configured? defined?(::ActiveRecord) && !::ActiveRecord::Base.configurations.blank? end def transactional_protection_start return unless active_record_configured? ::ActiveRecord::Base.connection.increment_open_transactions ::ActiveRecord::Base.connection.begin_db_transaction end def transactional_protection_cleanup return unless active_record_configured? if ::ActiveRecord::Base.connection.open_transactions != 0 ::ActiveRecord::Base.connection.rollback_db_transaction ::ActiveRecord::Base.connection.decrement_open_transactions end ::ActiveRecord::Base.clear_active_connections! end end end end Rspec.configure do |c| c.include Rspec::Rails::TransactionalDatabaseSupport c.before { transactional_protection_start } c.after { transactional_protection_cleanup } end
Version data entries
8 entries across 8 versions & 1 rubygems