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

#cleaning, 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_classObject



50
51
52
53
54
55
56
57
58
# File 'lib/database_cleaner/active_record/base.rb', line 50

def connection_class
  @connection_class ||= if db && !db.is_a?(Symbol)
                          db
                        elsif connection_hash
                          lookup_from_connection_pool || establish_connection
                        else
                          ::ActiveRecord::Base
                        end
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 && self.db.is_a?(Symbol) && File.file?(ActiveRecord.config_file_location)
    connection_details = YAML::load(ERB.new(IO.read(ActiveRecord.config_file_location)).result)
    @connection_hash   = valid_config(connection_details)[self.db.to_s]
  end
end

#valid_config(connection_file) ⇒ Object



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

def valid_config(connection_file)
  if !::ActiveRecord::Base.configurations.nil? && !::ActiveRecord::Base.configurations.empty?
    if connection_file != ::ActiveRecord::Base.configurations
      return ::ActiveRecord::Base.configurations
    end
  end
  connection_file
end