Sha256: 79dda8c862208413106e996c2834b3a3a914440cf7b59470a72d423d3bc00265

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'rails'

def unit_example?(metadata)
  metadata[:file_path] =~ %r{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 redis?

    if active_record? && 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 active_record? && 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

5 entries across 5 versions & 1 rubygems

Version Path
rpush-2.7.0-java spec/unit_spec_helper.rb
rpush-2.7.0 spec/unit_spec_helper.rb
rpush-2.6.0-java spec/unit_spec_helper.rb
rpush-2.6.0 spec/unit_spec_helper.rb
rpush-2.5.0 spec/unit_spec_helper.rb