Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

trys to make a little more sense out of this horrible design

  • Loading branch information...
commit c06754a540076faf5761d970eff72f20e0c964ec 1 parent 4cdaaa0
@bmabey bmabey authored
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/database_cleaner/active_record/base.rb
View
20 lib/database_cleaner/active_record/base.rb
@@ -42,20 +42,34 @@ def create_connection_klass
Class.new(::ActiveRecord::Base)
end
+
+
def connection_klass
- return ::ActiveRecord::Base unless connection_hash
+ 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
+
+ def lookup_from_connection_pool
if ::ActiveRecord::Base.respond_to?(:descendants)
database_name = connection_hash["database"] || connection_hash[:database]
models = ::ActiveRecord::Base.descendants
- klass = models.detect {|m| m.connection_pool.spec.config[:database] == database_name}
- return klass if klass
+ models.detect {|m| m.connection_pool.spec.config[:database] == database_name}
end
+ end
+ def establish_connection
klass = create_connection_klass
klass.send :establish_connection, connection_hash
klass
end
+
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.