Sha256: 8b8e494e3776df67f8b08dc2ded893e8302c51429cb22467a632cda8411eac6d

Contents?: true

Size: 689 Bytes

Versions: 8

Compression:

Stored size: 689 Bytes

Contents

module TestData
  class SavePoint
    attr_reader :name, :transaction

    def initialize(name)
      @name = name
      @transaction = connection.begin_transaction(joinable: false, _lazy: false)
    end

    def active?
      !@transaction.state.finalized?
    end

    def rollback!
      warn_if_not_rollbackable!
      while active?
        connection.rollback_transaction
      end
    end

    private

    def connection
      ActiveRecord::Base.connection
    end

    def warn_if_not_rollbackable!
      return if active?
      TestData.log.warn(
        "Attempted to roll back transaction save point '#{name}', but its state was #{@transaction.state}"
      )
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
test_data-0.3.2 lib/test_data/save_point.rb
test_data-0.3.1 lib/test_data/save_point.rb
test_data-0.3.0 lib/test_data/save_point.rb
test_data-0.2.2 lib/test_data/save_point.rb
test_data-0.2.1 lib/test_data/save_point.rb
test_data-0.2.0 lib/test_data/save_point.rb
test_data-0.1.0 lib/test_data/save_point.rb
test_data-0.0.2 lib/test_data/save_point.rb