1 print
"Using native SQLite3\n"
2 require_dependency
'models/course'
4 ActiveRecord
::Base.logger
= Logger
.new("debug.log")
6 class SqliteError
< StandardError
9 BASE_DIR
= FIXTURES_ROOT
10 sqlite_test_db
= "#{BASE_DIR}/fixture_database.sqlite3"
11 sqlite_test_db2
= "#{BASE_DIR}/fixture_database_2.sqlite3"
13 def make_connection(clazz
, db_file
)
14 ActiveRecord
::Base.configurations
= { clazz
.name
=> { :adapter => 'sqlite3', :database => db_file
, :timeout => 5000 } }
15 unless File
.exist
?(db_file
)
16 puts
"SQLite3 database not found at #{db_file}. Rebuilding it."
17 sqlite_command
= %Q{sqlite3 "#{db_file}" "create table a (a integer); drop table a;"}
18 puts "Executing '#{sqlite_command}'"
19 raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
21 clazz.establish_connection(clazz.name)
24 make_connection(ActiveRecord::Base, sqlite_test_db)
25 make_connection(Course, sqlite_test_db2)