Module: ActiveRecord::ConnectionAdapters::DatabaseStatements

Defined in:
lib/prefactory/active_record_integration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commit_at_open_transaction_levelObject



35
36
37
# File 'lib/prefactory/active_record_integration.rb', line 35

def commit_at_open_transaction_level
  @commit_at_open_transaction_level || 1
end

Instance Method Details

#transaction_with_transactional_specs(options = {}, &block) ⇒ Object Also known as: transaction



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/prefactory/active_record_integration.rb', line 39

def transaction_with_transactional_specs(options = {}, &block)
  return_value = nil
  rolled_back = false

  transaction_without_transactional_specs(options.merge(:requires_new => true)) do
    begin
      return_value = yield
    rescue StandardError => e
      rolled_back = true
      raise e
    end
    if !rolled_back && open_transactions <= commit_at_open_transaction_level + 1
      current_transaction.instance_variable_set(:@fake_commit, true)
      current_transaction.instance_variable_set(:@run_commit_callbacks, true)
    end
  end
  return_value
end