2021-02-01 17:58:25 +00:00
|
|
|
require 'rake'
|
|
|
|
|
require_relative '../lib/jam_ruby/test_support'
|
|
|
|
|
|
2012-08-06 03:01:00 +00:00
|
|
|
class SpecDb
|
|
|
|
|
|
|
|
|
|
TEST_DB_NAME="jam_ruby_test"
|
|
|
|
|
|
2012-10-21 01:55:49 +00:00
|
|
|
TEST_USER_ID = "1" #test@jamkazam.com
|
2021-02-01 17:58:25 +00:00
|
|
|
|
|
|
|
|
# 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}")
|
|
|
|
|
# if ENV['TABLESPACE']
|
|
|
|
|
# conn.exec("CREATE DATABASE #{TEST_DB_NAME} WITH TABLESPACE=#{ENV['TABLESPACE']}")
|
|
|
|
|
# else
|
|
|
|
|
# conn.exec("CREATE DATABASE #{TEST_DB_NAME}")
|
|
|
|
|
# end
|
|
|
|
|
|
2014-05-16 19:39:37 +00:00
|
|
|
|
2021-02-01 17:58:25 +00:00
|
|
|
# JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME, :user => "postgres", :password => "postgres", :host => "localhost")
|
|
|
|
|
# end
|
2014-05-16 19:39:37 +00:00
|
|
|
|
2021-02-01 17:58:25 +00:00
|
|
|
def self.recreate_database
|
|
|
|
|
Rake.application.init
|
|
|
|
|
Rake.application.load_rakefile
|
|
|
|
|
Rails.env = ENV['RAILS_ENV'] = 'test'
|
|
|
|
|
begin
|
|
|
|
|
Rake::Task['db:drop'].invoke
|
|
|
|
|
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
|
|
|
|
|
puts "Database does not exist"
|
|
|
|
|
end
|
|
|
|
|
Rake::Task['db:create'].invoke
|
|
|
|
|
Rake::Task['db:migrate'].invoke
|
2012-08-06 03:01:00 +00:00
|
|
|
end
|
2021-02-01 17:58:25 +00:00
|
|
|
|
|
|
|
|
|
2012-09-18 03:37:17 +00:00
|
|
|
end
|