@@ -49,6 +49,14 @@ def self.db_path
4949 @db_path ||= root_path . join ( "db" , "db.sqlite3" )
5050 end
5151
52+ def self . db_uri
53+ @db_url ||= URI ( ENV [ "DATABASE_URL" ] || "sqlite3://#{ db_path } " )
54+ end
55+
56+ def self . db_name
57+ db_uri . path [ 1 ..-1 ]
58+ end
59+
5260 def self . application_file
5361 @application_file ||= begin
5462 current = Dir [ root_path . join ( "config/applications/rails-*.rb" ) ]
@@ -61,14 +69,24 @@ def self.application_file
6169
6270 def self . load_test_schema
6371 @__schema_loaded__ ||= begin
64- # This is more reliable than setting config/database.yml
65- ENV [ "DATABASE_URL" ] = "sqlite3://#{ db_path } "
66-
6772 # Silence migrations output
6873 ActiveRecord ::Migration . verbose = false
6974
7075 # We need to connect manually here
71- ActiveRecord ::Base . establish_connection ( adapter : "sqlite3" , database : db_path )
76+ case db_uri . scheme
77+ when "postgresql"
78+ ActiveRecord ::Base . establish_connection (
79+ adapter : db_uri . scheme ,
80+ host : db_uri . host ,
81+ username : db_uri . user ,
82+ password : db_uri . password ,
83+ database : db_uri . path [ 1 ..-1 ]
84+ )
85+ else
86+ ActiveRecord ::Base . establish_connection (
87+ adapter : db_uri . scheme , database : db_uri . path [ 1 ..-1 ]
88+ )
89+ end
7290
7391 # Load schema from db/schema.rb into the current connection
7492 require Test ::Application . schema_file
0 commit comments