Class: Cucumber::Rails::Database::SharedConnectionStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/cucumber/rails/database/shared_connection_strategy.rb

Instance Method Summary collapse

Methods inherited from Strategy

#after, #initialize

Constructor Details

This class inherits a constructor from Cucumber::Rails::Database::Strategy

Instance Method Details

#before_jsObject



7
8
9
10
11
12
13
14
15
# File 'lib/cucumber/rails/database/shared_connection_strategy.rb', line 7

def before_js
  # Forces all threads to share a connection on a per-model basis,
  # as connections may vary per model as per establish_connection. This works
  # on Capybara because it starts the web server in a thread.
  ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
  ActiveRecord::Base.descendants.each do |model|
    model.shared_connection = model.connection
  end
end

#before_non_jsObject



17
18
19
20
21
22
23
# File 'lib/cucumber/rails/database/shared_connection_strategy.rb', line 17

def before_non_js
  # Do not use a shared connection unless we're in a @javascript scenario
  ActiveRecord::Base.shared_connection = nil
  ActiveRecord::Base.descendants.each do |model|
    model.shared_connection = nil
  end
end