Module: DatabaseCleaner::ActiveRecord::Base

Includes:
Generic::Base
Included in:
Surgicalstrike, 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.



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

def connection_hash
  @connection_hash
end

Instance Method Details

#connection_klassObject



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

def connection_klass
  return ::ActiveRecord::Base unless connection_hash
  klass = create_connection_klass
  klass.send :establish_connection, connection_hash
  klass
end

#create_connection_klassObject



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

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

#dbObject



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

def db
  @db || super
end

#db=(desired_db) ⇒ Object



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

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

#load_configObject



34
35
36
37
38
39
# 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