Class: ActiveRecordSafetyListener

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/spec/rails/story_adapter.rb

Instance Method Summary collapse

Instance Method Details

#scenario_started(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/spec/rails/story_adapter.rb', line 41

def scenario_started(*args)
  if defined?(ActiveRecord::Base)
    if ActiveRecord::Base.connection.respond_to?(:increment_open_transactions)
      ActiveRecord::Base.connection.increment_open_transactions
    else
      ActiveRecord::Base.__send__ :increment_open_transactions
    end
  end
  ActiveRecord::Base.connection.begin_db_transaction
end

#scenario_succeeded(*args) ⇒ Object Also known as: scenario_pending, scenario_failed



52
53
54
55
56
57
58
59
60
61
# File 'lib/spec/rails/story_adapter.rb', line 52

def scenario_succeeded(*args)
  if defined?(ActiveRecord::Base)
    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