module DatabaseCleaner::ActiveRecord::Base

Attributes

connection_hash[RW]

Public Instance Methods

connection_class() click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 45
def connection_class
  @connection_class ||= 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
create_connection_class() click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 41
def create_connection_class
  Class.new(::ActiveRecord::Base)
end
db() click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 30
def db
  @db || super
end
db=(desired_db) click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 25
def db=(desired_db)
  @db = desired_db
  load_config
end
load_config() click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 34
def load_config
  if self.db != :default && File.file?(ActiveRecord.config_file_location)
    connection_details   = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
    @connection_hash = connection_details[self.db.to_s]
  end
end