jam-cloud/web/spec/spec_db.rb

53 lines
2.0 KiB
Ruby
Raw Normal View History

require 'yaml'
2012-09-01 12:31:26 +00:00
class SpecDb
# TEST_DB_NAME="jam_web_test"
2012-09-01 12:31:26 +00:00
# def self.recreate_database(db_config)
# recreate_database_jdbc(db_config)
# end
2012-09-01 12:31:26 +00:00
def self.reset_test_database
ENV['RAILS_ENV'] = 'test'
db_config = YAML::load(File.open('config/database.yml'))[ENV['RAILS_ENV']]
db_test_name = db_config["database"]
# jump into the 'postgres' database, just so we have somewhere to 'land' other than our test db,
# since we are going to drop/recreate it
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
ActiveRecord::Base.establish_connection(db_config_admin)
2012-11-18 02:37:36 +00:00
ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{db_test_name}")
ActiveRecord::Base.connection.execute("CREATE DATABASE #{db_test_name}")
2012-09-01 12:31:26 +00:00
end
def self.recreate_database
self.reset_test_database
JamRuby::TestSupport.migrate_database
2012-09-01 12:31:26 +00:00
end
# def self.recreate_database_jdbc(db_config)
# db_test_name = db_config["database"]
# # jump into the 'postgres' database, just so we have somewhere to 'land' other than our test db,
# # since we are going to drop/recreate it
# db_config["database"] = "postgres"
# ActiveRecord::Base.establish_connection(db_config)
# ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{db_test_name}")
# if ENV['TABLESPACE']
# ActiveRecord::Base.connection.execute("CREATE DATABASE #{db_test_name} WITH tablespace=#{ENV["TABLESPACE"]}")
# else
# ActiveRecord::Base.connection.execute("CREATE DATABASE #{db_test_name}")
# end
# db_config["database"] = db_test_name
# JamDb::Migrator.new.migrate(:dbname => db_config["database"], :user => db_config["username"], :password => db_config["password"], :host => db_config["host"])
# end
# def self.recreate_database_pg
# conn = PG::Connection.open("dbname=postgres")
# conn.exec("DROP DATABASE IF EXISTS #{TEST_DB_NAME}")
# conn.exec("CREATE DATABASE #{TEST_DB_NAME}")
# JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME)
# end
2012-09-01 12:31:26 +00:00
end