Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/database_cleaner/sequel/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
module DatabaseCleaner
module Sequel
class Transaction < Base
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

def start
self.class.check_fiber_brokenness

@fibers ||= []
db = self.db
f = Fiber.new do
Expand All @@ -19,6 +30,10 @@ def clean
f = @fibers.pop
f.resume
end

def cleaning
self.db.transaction(:rollback => :always, :savepoint => true, :auto_savepoint => true) { yield }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/database_cleaner/sequel/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module DatabaseCleaner
module Sequel
VERSION = "2.0.0"
VERSION = "2.0.1"
end
end