7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/schema_dev/rspec.rb', line 7
def self.db_connect
db = ENV['SCHEMA_DEV_DB']
ruby = "#{RUBY_ENGINE}-#{RUBY_VERSION}"
rails = "rails-#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
root = Pathname.new('tmp')
root.mkpath
configuration = case db
when 'mysql'
{
:adapter => 'mysql',
:database => 'schema_plus_test',
:username => ENV.fetch('MYSQL_DB_USER', 'schema_plus'),
:encoding => 'utf8',
:min_messages => 'warning'
}
when 'mysql2'
{
:adapter => 'mysql2',
:database => 'schema_plus_test',
:username => ENV.fetch('MYSQL_DB_USER', 'schema_plus'),
:encoding => 'utf8',
:min_messages => 'warning'
}
when 'postgresql'
{
:adapter => 'postgresql',
:username => ENV['POSTGRESQL_DB_USER'],
:database => 'schema_plus_test',
:min_messages => 'warning'
}
when 'sqlite3'
{
:adapter => 'sqlite3',
:database => root.join('schema_plus.sqlite3')
}
else
raise "Unknown db adapter #{db.inspect}"
end
ActiveRecord::Base.logger = Logger.new(root.join("#{ruby}.#{rails}.#{db}.log").open("w"))
ActiveRecord::Base.configurations = { 'schema_dev' => configuration }
ActiveRecord::Base.establish_connection :schema_dev
case db
when 'sqlite3'
ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"
end
end
|