Module: DatabaseCleaner::ActiveRecord::Base

Includes:
Generic::Base
Included in:
Transaction, Truncation
Defined in:
lib/database_cleaner/active_record/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generic::Base

included

Instance Attribute Details

#connection_hashObject

Returns the value of attribute connection_hash.



22
23
24
# File 'lib/database_cleaner/active_record/base.rb', line 22

def connection_hash
  @connection_hash
end

Instance Method Details

#connection_klassObject



44
45
46
47
48
49
# File 'lib/database_cleaner/active_record/base.rb', line 44

def connection_klass
  return ::ActiveRecord::Base if connection_hash.nil?
  klass = create_connection_klass
  klass.send :establish_connection, connection_hash
  klass
end

#create_connection_klassObject



40
41
42
# File 'lib/database_cleaner/active_record/base.rb', line 40

def create_connection_klass
  Class.new(::ActiveRecord::Base)
end

#dbObject



29
30
31
# File 'lib/database_cleaner/active_record/base.rb', line 29

def db
  @db || super
end

#db=(desired_db) ⇒ Object



24
25
26
27
# File 'lib/database_cleaner/active_record/base.rb', line 24

def db=(desired_db)
  @db = desired_db
  load_config
end

#load_configObject



33
34
35
36
37
38
# File 'lib/database_cleaner/active_record/base.rb', line 33

def load_config
  if File.file?(ActiveRecord.config_file_location)
    connection_details   = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
    self.connection_hash = connection_details[self.db.to_s]
  end
end