Functional tests now work properly, bearing in mind whether a user is logged in or...
[depot.git] / vendor / rails / activerecord / test / connections / native_sqlite3 / connection.rb
1 print "Using native SQLite3\n"
2 require_dependency 'models/course'
3 require 'logger'
4 ActiveRecord::Base.logger = Logger.new("debug.log")
5
6 class SqliteError < StandardError
7 end
8
9 BASE_DIR = FIXTURES_ROOT
10 sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
11 sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
12
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)
20 end
21 clazz.establish_connection(clazz.name)
22 end
23
24 make_connection(ActiveRecord::Base, sqlite_test_db)
25 make_connection(Course, sqlite_test_db2)