Class: RSpec::Multicore::Rails::DatabaseManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/multicore/rails/database_manager.rb

Overview

Names, prepares, and connects worker-owned ActiveRecord databases.

Instance Method Summary collapse

Constructor Details

#initializeDatabaseManager

Returns a new instance of DatabaseManager.



11
12
13
14
# File 'lib/rspec/multicore/rails/database_manager.rb', line 11

def initialize
  ensure_test_environment!
  @base_config = ActiveRecord::Base.connection_db_config
end

Instance Method Details

#connect_worker(slot) ⇒ Object



16
17
18
19
# File 'lib/rspec/multicore/rails/database_manager.rb', line 16

def connect_worker(slot)
  ActiveRecord::Base.connection_handler.clear_all_connections!
  ActiveRecord::Base.establish_connection(config_for(slot))
end

#database_for(slot) ⇒ Object



31
# File 'lib/rspec/multicore/rails/database_manager.rb', line 31

def database_for(slot) = slot == 1 ? base_database : suffixed_database(slot)

#drop_workersObject



28
# File 'lib/rspec/multicore/rails/database_manager.rb', line 28

def drop_workers = worker_slots.drop(1).each { drop(_1) }

#prepare_allObject



21
22
23
24
25
26
# File 'lib/rspec/multicore/rails/database_manager.rb', line 21

def prepare_all
  worker_slots.each do |slot|
    purge(slot)
    ActiveRecord::Tasks::DatabaseTasks.load_schema(hash_config_for(slot))
  end
end

#workersObject



30
# File 'lib/rspec/multicore/rails/database_manager.rb', line 30

def workers = RSpec::Multicore.workers