2012-08-17 03:22:31 +00:00
|
|
|
class SpecDb
|
|
|
|
|
|
2021-02-01 17:58:25 +00:00
|
|
|
# TEST_DB_NAME="jam_websockets_test"
|
|
|
|
|
|
|
|
|
|
# def self.recreate_database
|
|
|
|
|
# conn = PG::Connection.open("dbname=postgres user=postgres password=postgres host=localhost")
|
|
|
|
|
# conn.exec("DROP DATABASE IF EXISTS #{TEST_DB_NAME}")
|
|
|
|
|
# conn.exec("CREATE DATABASE #{TEST_DB_NAME}")
|
|
|
|
|
# JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME, :user => "postgres", :password => "postgres", :host => "localhost")
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{db_test_name}")
|
|
|
|
|
ActiveRecord::Base.connection.execute("CREATE DATABASE #{db_test_name}")
|
|
|
|
|
end
|
|
|
|
|
|
2012-08-17 03:22:31 +00:00
|
|
|
|
2012-10-23 00:58:57 +00:00
|
|
|
def self.recreate_database
|
2021-02-01 17:58:25 +00:00
|
|
|
self.reset_test_database
|
|
|
|
|
JamRuby::TestSupport.migrate_database
|
2012-08-17 03:22:31 +00:00
|
|
|
end
|
2012-10-23 00:58:57 +00:00
|
|
|
|
2012-08-17 03:22:31 +00:00
|
|
|
end
|