Class: DatabaseCleaner::Sequel::Transaction

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/database_cleaner/sequel/transaction.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#db, #db=

Methods included from Generic::Base

#db, included

Class Method Details

.check_fiber_brokennessObject



7
8
9
10
11
12
13
14
# File 'lib/database_cleaner/sequel/transaction.rb', line 7

def self.check_fiber_brokenness
  if !@checked_fiber_brokenness && Fiber.new { Thread.current }.resume != Thread.current
    raise RuntimeError, "This ruby engine's Fibers are not compatible with Sequel's connection pool. " +
      "To work around this, please use DatabaseCleaner.cleaning with a block instead of " +
      "DatabaseCleaner.start and DatabaseCleaner.clean"
  end
  @checked_fiber_brokenness = true
end

Instance Method Details

#cleanObject



30
31
32
33
# File 'lib/database_cleaner/sequel/transaction.rb', line 30

def clean
  f = @fibers.pop
  f.resume
end

#cleaningObject



35
36
37
# File 'lib/database_cleaner/sequel/transaction.rb', line 35

def cleaning
  self.db.transaction(:rollback => :always, :savepoint => true) { yield }
end

#startObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/database_cleaner/sequel/transaction.rb', line 16

def start
  self.class.check_fiber_brokenness

  @fibers ||= []
  db = self.db
  f = Fiber.new do
    db.transaction(:rollback => :always, :savepoint => true) do
      Fiber.yield
    end
  end
  f.resume
  @fibers << f
end