diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-03-20 17:49:57 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-20 17:56:46 +0000 |
commit | 4a582aa7caf31faa87f435b8ae39fdb85fab1042 (patch) | |
tree | eef73c4ac12f5d7dc8bf8555b4339513a76f7dc7 /activemodel/test/cases | |
parent | 37283a6aaec244cb484e24b3e9ff165e89eadd64 (diff) | |
download | rails-4a582aa7caf31faa87f435b8ae39fdb85fab1042.tar.gz rails-4a582aa7caf31faa87f435b8ae39fdb85fab1042.tar.bz2 rails-4a582aa7caf31faa87f435b8ae39fdb85fab1042.zip |
Use mattr_accessor in TestsDatabase instead of setup method
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/tests_database.rb | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/activemodel/test/cases/tests_database.rb b/activemodel/test/cases/tests_database.rb index cb5cda98f5..0f4475fa2d 100644 --- a/activemodel/test/cases/tests_database.rb +++ b/activemodel/test/cases/tests_database.rb @@ -6,25 +6,35 @@ require 'active_record/fixtures' module ActiveModel module TestsDatabase + mattr_accessor :connected + def self.included(base) - ActiveRecord::Base.logger = Logger.new("debug.log") - ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') + unless self.connected + setup_connection + setup_schema + end base.send :include, ActiveRecord::TestFixtures - base.setup :setup_database end - def setup_database - unless $schema_file_loaded - begin - # TODO : May the better way be with you - original, $stdout = $stdout, StringIO.new - load(SCHEMA_FILE) - ensure - $stdout = original - end + def self.setup_schema + original, $stdout = $stdout, StringIO.new + load(SCHEMA_FILE) + ensure + $stdout = original + self.connected = true + end - $schema_file_loaded = true + def self.setup_connection + defaults = { :database => ':memory:' } + begin + adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' + options = defaults.merge :adapter => adapter, :timeout => 500 + ActiveRecord::Base.establish_connection(options) + rescue Exception + $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.' + options = defaults.merge :adapter => 'sqlite' + ActiveRecord::Base.establish_connection(options) end end end |