Module: Merb::Test::Helpers::ActiveRecord::ClassMethods

Included in:
World::Base
Defined in:
lib/merb_cucumber/helpers/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#use_transactional_fixturesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/merb_cucumber/helpers/activerecord.rb', line 8

def use_transactional_fixtures
  # Let's set a transaction on the ActiveRecord connection when starting a new scenario
  $main.Before do
    if ::ActiveRecord::Base.connection.respond_to?(:increment_open_transactions)
      ::ActiveRecord::Base.connection.increment_open_transactions
    else
      ::ActiveRecord::Base.send :increment_open_transactions
    end
    ::ActiveRecord::Base.connection.begin_db_transaction
  end

  # Going with a rollback after every step in the scenario is executed
  $main.After do
    ::ActiveRecord::Base.connection.rollback_db_transaction
    if ::ActiveRecord::Base.connection.respond_to?(:decrement_open_transactions)
      ::ActiveRecord::Base.connection.decrement_open_transactions
    else
      ::ActiveRecord::Base.send :decrement_open_transactions
    end
  end
end