2009-03-20 11:07:49 -04:00
|
|
|
require 'logger'
|
|
|
|
|
2010-02-23 20:31:17 -05:00
|
|
|
$:.unshift(File.dirname(__FILE__) + '/../../../activerecord/lib')
|
2009-03-20 11:07:49 -04:00
|
|
|
require 'active_record'
|
|
|
|
|
|
|
|
module ActiveModel
|
2009-03-20 12:02:12 -04:00
|
|
|
module TestsDatabase
|
2009-03-20 13:49:57 -04:00
|
|
|
mattr_accessor :connected
|
|
|
|
|
2009-03-20 11:07:49 -04:00
|
|
|
def self.included(base)
|
2009-03-20 13:49:57 -04:00
|
|
|
unless self.connected
|
|
|
|
setup_connection
|
|
|
|
setup_schema
|
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
base.send :include, ActiveRecord::TestFixtures
|
|
|
|
end
|
|
|
|
|
2009-03-20 13:49:57 -04:00
|
|
|
def self.setup_schema
|
|
|
|
original, $stdout = $stdout, StringIO.new
|
|
|
|
load(SCHEMA_FILE)
|
|
|
|
ensure
|
|
|
|
$stdout = original
|
|
|
|
self.connected = true
|
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2009-03-20 13:49:57 -04:00
|
|
|
def self.setup_connection
|
|
|
|
defaults = { :database => ':memory:' }
|
2009-08-17 08:56:59 -04:00
|
|
|
|
|
|
|
adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'
|
|
|
|
options = defaults.merge :adapter => adapter, :timeout => 500
|
|
|
|
ActiveRecord::Base.establish_connection(options)
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|