Sha256: 9d2ba0252950b21d7c749c39769cf4ea2910e34a1d05a4cb2e88b8e47a0f569a

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
require 'rails'

def unit_example?(metadata)
  metadata[:file_path] =~ /spec\/unit/
end

def rails4?
  ::Rails::VERSION::STRING >= '4'
end

RSpec.configure do |config|
  config.before(:each) do
    Modis.with_connection do |redis|
      redis.keys('rpush:*').each { |key| redis.del(key) }
    end

    if unit_example?(self.class.metadata)
      connection = ActiveRecord::Base.connection

      if rails4?
        connection.begin_transaction joinable: false
      else
        connection.increment_open_transactions
        connection.transaction_joinable = false
        connection.begin_db_transaction
      end
    end
  end

  config.after(:each) do
    if unit_example?(self.class.metadata)
      connection = ActiveRecord::Base.connection

      if rails4?
        connection.rollback_transaction if connection.transaction_open?
      else
        if connection.open_transactions != 0
          connection.rollback_db_transaction
          connection.decrement_open_transactions
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpush-2.3.2-java spec/unit_spec_helper.rb
rpush-2.3.2 spec/unit_spec_helper.rb