11
11
require 'active_record'
12
12
require 'active_support/core_ext/array'
13
13
14
+ puts "Using ActiveRecord #{ ActiveRecord . gem_version } and #{ RUBY_ENGINE } #{ RUBY_ENGINE_VERSION } as #{ RUBY_VERSION } "
14
15
15
16
# Start Simplecov
16
17
if RUBY_ENGINE == 'ruby'
20
21
end
21
22
end
22
23
23
- database_file = SecureRandom . hex
24
- ActiveRecord ::Base . configurations = debug = {
24
+ primary_database_url = ENV [ 'DATABASE_URL' ] . presence || "sqlite3://tmp/closure_tree_test"
25
+ secondary_database_url = ENV [ 'SECONDARY_DATABASE_URL' ] . presence || "sqlite3://tmp/closure_tree_test-s"
26
+
27
+ puts "Using primary database #{ primary_database_url } "
28
+ puts "Using secondary database #{ secondary_database_url } "
29
+
30
+ ActiveRecord ::Base . configurations = {
25
31
default_env : {
26
- url : ENV [ 'DATABASE_URL' ] . presence || "sqlite3:// #{ Dir . tmpdir } / #{ database_file } .sqlite3" ,
32
+ url : primary_database_url ,
27
33
properties : { allowPublicKeyRetrieval : true } # for JRuby madness
28
34
} ,
29
35
secondary_env : {
30
- url : ENV [ 'SECONDARY_DATABASE_URL' ] . presence || "sqlite3:// #{ Dir . tmpdir } / #{ database_file } -s.sqlite3" ,
36
+ url : secondary_database_url ,
31
37
properties : { allowPublicKeyRetrieval : true } # for JRuby madness
32
38
}
33
39
}
34
40
35
- puts "Testing with #{ debug } "
36
-
37
41
# Configure ActiveRecord
38
42
ActiveRecord ::Migration . verbose = false
39
43
ActiveRecord ::Base . table_name_prefix = ENV [ 'DB_PREFIX' ] . to_s
@@ -75,16 +79,13 @@ def sqlite?
75
79
# disable monkey patching
76
80
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
77
81
config . disable_monkey_patching!
78
-
79
- if sqlite?
80
82
config . before ( :suite ) do
81
- ENV [ 'FLOCK_DIR' ] = Dir . mktmpdir
83
+ ENV [ 'FLOCK_DIR' ] = Dir . mktmpdir if sqlite?
82
84
end
83
85
84
86
config . after ( :suite ) do
85
- FileUtils . remove_entry_secure ENV [ 'FLOCK_DIR' ]
87
+ FileUtils . remove_entry_secure ( ENV [ 'FLOCK_DIR' ] ) if sqlite?
86
88
end
87
- end
88
89
end
89
90
90
91
# Configure parallel specs
@@ -94,14 +95,16 @@ def sqlite?
94
95
# See: https://github.com/ClosureTree/with_advisory_lock
95
96
ENV [ 'WITH_ADVISORY_LOCK_PREFIX' ] ||= SecureRandom . hex
96
97
97
- ActiveRecord ::Base . connection . recreate_database ( "closure_tree_test" ) unless sqlite?
98
- puts "Testing with #{ env_db } database, ActiveRecord #{ ActiveRecord . gem_version } and #{ RUBY_ENGINE } #{ RUBY_ENGINE_VERSION } as #{ RUBY_VERSION } "
99
98
# Require our gem
100
99
require 'closure_tree'
101
100
101
+ ActiveRecord ::Tasks ::DatabaseTasks . create_current ( 'default_env' , 'test' )
102
+ ActiveRecord ::Tasks ::DatabaseTasks . create_current ( 'secondary_env' , 'test' )
103
+
102
104
# Load test helpers
103
105
require_relative 'support/schema'
104
106
require_relative 'support/models'
105
107
require_relative 'support/helpers'
106
108
require_relative 'support/exceed_query_limit'
107
109
require_relative 'support/query_counter'
110
+ puts "Testing with #{ env_db } database"
0 commit comments