Sha256: ca40a40d5c2b82b4d60dacd03ada2c16d5e48a6154f356235001e281b1578beb
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
require 'database_cleaner/generic/base' require 'active_record' require 'erb' module DatabaseCleaner module ActiveRecord def self.available_strategies %w[truncation transaction deletion] end def self.config_file_location=(path) @config_file_location = path end def self.config_file_location @config_file_location ||= "#{DatabaseCleaner.app_root}/config/database.yml" end module Base include ::DatabaseCleaner::Generic::Base attr_accessor :connection_hash def db=(desired_db) @db = desired_db load_config end def db @db || super end 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 def create_connection_klass Class.new(::ActiveRecord::Base) end def connection_klass return ::ActiveRecord::Base if connection_hash.nil? klass = create_connection_klass klass.send :establish_connection, connection_hash klass end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
database_cleaner-0.7.0 | lib/database_cleaner/active_record/base.rb |