Sha256: 2b077c3f12a2ff152a4cadfe9204a6512c2eecbe9350d37ec4cd3d3958524b33

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

module AdapterTestHelper

  def self.before_all(adapter_name)
    method = "#{adapter_name}_before_all"
    send method if respond_to? method
  end

  def self.after_all(adapter_name)
    method = "#{adapter_name}_after_all"
    send method if respond_to? method
  end

  def self.before_each(adapter_name)
    method = "#{adapter_name}_before_each"
    send method if respond_to? method
  end

  def self.after_each(adapter_name)
    method = "#{adapter_name}_after_each"
    send method if respond_to? method
  end

  private

  def self.sqlite3_before_each
    ActiveTenant.configuration.global = 'test'
    ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: "#{TEMP_PATH}/test.sqlite3"
    ActiveRecord::Base.connection
  end

  def self.sqlite3_after_each
    ActiveRecord::Base.connection.disconnect!
    Dir.glob("#{TEMP_PATH}/*.sqlite3").each do |file|
      FileUtils.rm(file)
    end
  end

  def self.postgresql_before_all
    ActiveTenant.configuration.global = 'public'
    config = {
        adapter: 'postgresql',
        database: 'active_tenant_test',
        schema_search_path: 'public',
        username: 'postgres',
        password: 'password'
    }
    ActiveRecord::Base.establish_connection config.merge database: 'postgres'
    ActiveRecord::Base.connection.drop_database config[:database] rescue nil
    ActiveRecord::Base.connection.create_database config[:database]
    ActiveRecord::Base.establish_connection config
  end

  def self.postgresql_after_all
    config = ActiveRecord::Base.connection_config
    ActiveRecord::Base.establish_connection config.merge database: 'postgres'
    ActiveRecord::Base.connection.drop_database config[:database]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_tenant-0.0.2 spec/support/adapter_test_helper.rb
active_tenant-0.0.1 spec/support/adapter_test_helper.rb