Updated Rakefile and test_helper to work with more adapters than just sqlite3.

This commit is contained in:
Zach Dennis 2010-03-13 20:20:55 -05:00
parent 61c1af6520
commit 459aeb6fee
2 changed files with 28 additions and 6 deletions

21
Rakefile Normal file
View file

@ -0,0 +1,21 @@
require 'rake/testtask'
task :default => [:test]
ADAPTERS = %w(mysql postgresql sqlite sqlite3 oracle)
desc "Runs generic database tests."
Rake::TestTask.new("test") { |t|
t.test_files = FileList["test/*_test.rb", "test/#{ENV['ARE_DB']}/**/*_test.rb"]
}
ADAPTERS.each do |adapter|
namespace :test do
desc "Runs unit tests for #{adapter} specific functionality"
task adapter do
ENV["ARE_DB"] = adapter
exec "rake test"
# exec replaces the current process, never gets here
end
end
end

View file

@ -1,6 +1,5 @@
ENV["RAILS_ENV"] = "test"
require 'pathname'
this_dir = Pathname.new File.dirname(__FILE__)
$LOAD_PATH << this_dir.join("../lib")
@ -57,22 +56,24 @@ end
# load test helpers
require "rails"
class MyApplication < Rails::Application ; end
adapter = "sqlite3"
adapter = ENV["ARE_DB"] || "sqlite3"
ActiveRecord::Base.logger = Logger.new("log/test.log")
ActiveRecord::Base.logger.level = Logger::DEBUG
ActiveRecord::Base.configurations["test"] = YAML.load(this_dir.join("database.yml").open)[adapter]
ActiveRecord::Base.establish_connection "test"
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |event, _, _, _, hsh|
ActiveRecord::Base.logger.info hsh[:sql]
end
require "factory_girl"
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file }
# Load base/generic schema
require this_dir.join("schema/version")
require this_dir.join("schema/generic_schema")
# Load adapter specific schema if one exists
adapter_schema = this_dir.join("schema/#{adapter}_schema")
adapter_schema = this_dir.join("schema/#{adapter}_schema.rb")
require adapter_schema if File.exists?(adapter_schema)
Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }