Sha256: 8bbcadb9d358440319d442c25d4bb73ff5dfa96ac7a91962499a511c5f74c1c0

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

# Author: Stephen Sykes
# http://pennysmalls.com

module SlimDbTestUtils
  DB_NAME = "slim_attributes_test"

  def self.db_config
    @config ||= YAML.load(File.read(File.dirname(__FILE__) + "/database.yml"))
    @config[DB_NAME]
  end

  def self.connect_and_create_db
    connect_with_config(db_config)
    unless ActiveRecord::Base.connected?  # database did not exist (as expected)
      connect_with_config(db_config.merge({"database"=>nil}))
      ActiveRecord::Base.connection.create_database(db_config["database"])
      connect_with_config(db_config)
    end
  end
  
  def self.connect_with_config(config)
    begin
      ActiveRecord::Base.establish_connection(config)
      ActiveRecord::Base.connection
    rescue Mysql::Error
    end
  end
  
  def self.remove_db
    if ActiveRecord::Base.connected?
      ActiveRecord::Base.connection.execute("DROP DATABASE #{db_config["database"]}")
    end
  end
  
  def self.import_sql(file)
    `mysql -p#{db_config["password"]} -u #{db_config["username"]} #{db_config["database"]} < #{File.dirname(__FILE__)}/#{file}`
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
ghazel-slim-attributes-0.6.3.1 test/slim_db_test_utils.rb
sdsykes-slim-attributes-0.6.2 test/slim_db_test_utils.rb
sdsykes-slim-attributes-0.6.3 test/slim_db_test_utils.rb
sdsykes-slim-attributes-0.6.4 test/slim_db_test_utils.rb
sdsykes-slim-attributes-0.6.6 test/slim_db_test_utils.rb
slim-attributes-0.7.7 test/slim_db_test_utils.rb
ghazel-slim-attributes-0.7.6.1 test/slim_db_test_utils.rb
slim-attributes-0.7.6 test/slim_db_test_utils.rb
slim-attributes-0.7.5 test/slim_db_test_utils.rb
slim-attributes-0.7.4 test/slim_db_test_utils.rb
slim-attributes-0.7.1 test/slim_db_test_utils.rb
slim-attributes-0.6.6 test/slim_db_test_utils.rb
slim-attributes-0.6.4 test/slim_db_test_utils.rb