From 64581a8875b47c3714bd3e29b1e59688c3ddd5a8 Mon Sep 17 00:00:00 2001 From: Ben Mabey Date: Sat, 25 Aug 2012 11:46:01 -0600 Subject: [PATCH] caches the connection class and allows DB's to be passed in as under the :db key per @kostya's patch Previous patch that did not merge cleanly any more: https://github.com/kostya/database_cleaner/commit/985beb3dd0a288117e1fc217c5c3011b914be224 --- lib/database_cleaner/active_record/base.rb | 14 +++++++------- lib/database_cleaner/base.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index 6ae5bdf..a8d6672 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -45,13 +45,13 @@ module DatabaseCleaner def connection_klass - if @db == :default || (@db.nil? && connection_hash.nil?) - ::ActiveRecord::Base - elsif connection_hash - lookup_from_connection_pool || establish_connection - else - @db # allows for an actual class to be passed in - end + @connection_klass ||= if @db == :default || (@db.nil? && connection_hash.nil?) + ::ActiveRecord::Base + elsif connection_hash + lookup_from_connection_pool || establish_connection + else + @db # allows for an actual class to be passed in + end end private diff --git a/lib/database_cleaner/base.rb b/lib/database_cleaner/base.rb index eb3cd8c..96e4b8e 100644 --- a/lib/database_cleaner/base.rb +++ b/lib/database_cleaner/base.rb @@ -8,7 +8,7 @@ module DatabaseCleaner else self.orm = desired_orm end - self.db = opts[:connection] if opts.has_key? :connection + self.db = opts[:connection] || opts[:db] if opts.has_key?(:connection) || opts.has_key?(:db) set_default_orm_strategy end