Sha256: 35162da1721907820ca0a9dc8a3475e22c79a748b2e017712c27e285baab1e00

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

class DBConnection
  def self.db
    @db ||= ActiveRecord::Base.establish_connection(
      configuration.merge(database: 'ar_sql_analyzer_test')
    )
  end

  def self.connection
    db.connection
  end

  def self.configuration
    {
      adapter: 'mysql2',
      host: 'localhost',
      encoding: 'utf8',
      usernamme: ENV["TRAVIS"] ? "travis" : "root"
    }
  end

  def self.setup_db
    conn = ActiveRecord::Base.establish_connection(configuration)
    conn.connection.execute <<-SQL
      CREATE DATABASE IF NOT EXISTS ar_sql_analyzer_test
    SQL
  end

  def self.reset
    connection.execute <<-SQL
      DROP TABLE IF EXISTS matching_table
    SQL

    connection.execute <<-SQL
      CREATE TABLE `matching_table` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `test_string` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    SQL

    connection.execute <<-SQL
      DROP TABLE IF EXISTS second_matching_table
    SQL

    connection.execute <<-SQL
      CREATE TABLE `second_matching_table` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `test_string` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    SQL

    connection.execute <<-SQL
      DROP TABLE IF EXISTS nonmatching_table
    SQL

    connection.execute <<-SQL
      CREATE TABLE `nonmatching_table` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `test_string` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    SQL
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_record-sql_analyzer-0.3.0 spec/support/db_connection.rb
active_record-sql_analyzer-0.2.2 spec/support/db_connection.rb
active_record-sql_analyzer-0.2.1 spec/support/db_connection.rb
active_record-sql_analyzer-0.2.0 spec/support/db_connection.rb
active_record-sql_analyzer-0.1.0 spec/support/db_connection.rb
active_record-sql_analyzer-0.0.8 spec/support/db_connection.rb
active_record-sql_analyzer-0.0.7 spec/support/db_connection.rb
active_record-sql_analyzer-0.0.6 spec/support/db_connection.rb
active_record-sql_analyzer-0.0.5 spec/support/db_connection.rb