module DatabaseCleaner::ActiveRecord::Base
Attributes
connection_hash[RW]
Public Class Methods
migration_table_name()
click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 60 def self.migration_table_name if ::ActiveRecord::VERSION::MAJOR < 5 ::ActiveRecord::Migrator.schema_migrations_table_name else ::ActiveRecord::SchemaMigration.table_name end end
Public Instance Methods
connection_class()
click to toggle source
# 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
db()
click to toggle source
Calls superclass method
DatabaseCleaner::Generic::Base#db
# 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 && 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)
click to toggle source
# 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
Private Instance Methods
establish_connection()
click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 78 def establish_connection ::ActiveRecord::Base.establish_connection(connection_hash) end
lookup_from_connection_pool()
click to toggle source
# File lib/database_cleaner/active_record/base.rb, line 70 def lookup_from_connection_pool if ::ActiveRecord::Base.respond_to?(:descendants) database_name = connection_hash["database"] || connection_hash[:database] models = ::ActiveRecord::Base.descendants models.detect { |m| m.connection_pool.spec.config[:database] == database_name } end end