aboutsummaryrefslogtreecommitdiffstats
path: root/spec/connections/sqlite3_connection.rb
blob: bae077711d9bf95092d5741d93dc9ca66fc6a4ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require "activerecord"
puts "Using native SQLite3"

db_file = "spec/fixtures/fixture_database.sqlite3"

ActiveRecord::Base.configurations = {
  "unit" => {
    :adapter  => 'sqlite3',
    :database => db_file,
    :timeout  => 5000
  }
}

unless File.exist?(db_file)
  puts "SQLite3 database not found at #{db_file}. Rebuilding it."
  FileUtils.mkdir_p(File.dirname(db_file))
  sqlite_command = %Q{sqlite3 "#{db_file}" "create table a (a integer); drop table a;"}
  puts "Executing '#{sqlite_command}'"
  raise "Seems that there is no sqlite3 executable available" unless system(sqlite_command)
end

ActiveRecord::Base.establish_connection("unit")