Sha256: 49eefd17c553a8739113062f79f9af6248344f8185326663beded48728e9d154

Contents?: true

Size: 1.08 KB

Versions: 33

Compression:

Stored size: 1.08 KB

Contents

require 'database_cleaner/sequel/base'
module DatabaseCleaner
  module Sequel
    class Transaction
      include ::DatabaseCleaner::Sequel::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
          db.transaction(:rollback => :always, :savepoint => true) do
            Fiber.yield
          end
        end
        f.resume
        @fibers << f
      end

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

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

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
database_cleaner-sequel-1.99.0 lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.99.0 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.99.0.beta adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-sequel-1.99.0.beta lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.5 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.4 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.3 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.2 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.1 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.0 adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-sequel-1.8.0 lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.8.0.beta adapters/database_cleaner-sequel/lib/database_cleaner/sequel/transaction.rb
database_cleaner-sequel-1.8.0.beta lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.7.0 lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.6.2 lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.6.1 lib/database_cleaner/sequel/transaction.rb
database_cleaner-1.6.0 lib/database_cleaner/sequel/transaction.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/sequel/transaction.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/sequel/transaction.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/sequel/transaction.rb