lib/slavery/transaction.rb in slavery-2.1.0 vs lib/slavery/transaction.rb in slavery-2.1.1

- old
+ new

@@ -1,18 +1,29 @@ module Slavery class Transaction + # The methods on ActiveSupport::TestCase which can potentially be used + # to determine if transactional fixtures are enabled + TEST_CONFIG_METHODS = [ + :use_transactional_tests, + :use_transactional_fixtures + ] + class << self def base_depth - @base_depth ||= begin - testcase = ActiveSupport::TestCase - if defined?(testcase) && - testcase.respond_to?(:use_transactional_fixtures) && - testcase.try(:use_transactional_fixtures) - 1 - else - 0 - end + @base_depth ||= if defined?(ActiveSupport::TestCase) && + transactional_fixtures_enabled? + then + 1 + else + 0 end + end + + private + + def transactional_fixtures_enabled? + config = ActiveSupport::TestCase + TEST_CONFIG_METHODS.any? {|m| config.respond_to?(m) and config.send(m) } end end end end