From 459aeb6fee4a9c4e3ae45432abcb6126c9cc2314 Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Sat, 13 Mar 2010 20:20:55 -0500 Subject: [PATCH] Updated Rakefile and test_helper to work with more adapters than just sqlite3. --- Rakefile | 21 +++++++++++++++++++++ test/test_helper.rb | 13 +++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 Rakefile diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4b0e189 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 5b4423d..6366568 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 } -