<commit_before>require 'test_after_commit/version'

module TestAfterCommit
end

ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
  def transaction_with_transactional_fixtures(*args)
    @test_open_transactions ||= 0
    transaction_without_transactional_fixtures(*args) do
      begin
        @test_open_transactions += 1
        result = yield
      rescue ActiveRecord::Rollback => e
        raise e
      else
        if @test_open_transactions == 1
          test_commit_records
        end
        result
      ensure
        @test_open_transactions -= 1
      end
    end
  end
  alias_method_chain :transaction, :transactional_fixtures

  def test_commit_records
    if ActiveRecord::VERSION::MAJOR == 3
      commit_transaction_records(false)
    else
      @transaction.commit_records
      @transaction.records.clear # prevent duplicate .commit!
      @transaction.instance_variable_get(:@state).set_state(nil)
    end
  end

  if ActiveRecord::VERSION::MAJOR == 3
    # The @_current_transaction_records is a stack of arrays, each one
    # containing the records associated with the corresponding transaction
    # in the transaction stack. This is used by the<commit_msg>Hugo/Emily fixing after_commit to fire with returning blocks<commit_after>require 'test_after_commit/version'

module TestAfterCommit
end

ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
  def transaction_with_transactional_fixtures(*args)
    @test_open_transactions ||= 0
    transaction_without_transactional_fixtures(*args) do
      begin
        @test_open_transactions += 1
        result = yield
      rescue ActiveRecord::Rollback => e
        rolled_back = true
        raise e
      ensure
        if @test_open_transactions == 1 && !rolled_back
          test_commit_records
        end
        @test_open_transactions -= 1
        result
      end
    end
  end
  alias_method_chain :transaction, :transactional_fixtures

  def test_commit_records
    if ActiveRecord::VERSION::MAJOR == 3
      commit_transaction_records(false)
    else
      @transaction.commit_records
      @transaction.records.clear # prevent duplicate .commit!
      @transaction.instance_variable_get(:@state).set_state(nil)
    end
  end

  if ActiveRecord::VERSION::MAJOR == 3
    # The @_current_transaction_records is a stack of arrays, each one
    # containing the records associated with the corresponding transaction
    # in the transaction stack. This is used by the
{'fraction_non_alphanumeric': 0.06242448650825614, 'fraction_numerical': 0.004832863471606927, 'mean_word_length': 3.380952380952381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1517865', 'n_tokens_mistral': 688, 'n_tokens_neox': 672, 'n_words': 174}