require 'rake' require_relative '../lib/jam_ruby/test_support' class SpecDb TEST_DB_NAME="jam_ruby_test" TEST_USER_ID = "1" #test@jamkazam.com # 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 # JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME, :user => "postgres", :password => "postgres", :host => "localhost") # end 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 end end