Skip to content

Commit

Permalink
keep sub-Rails connected to our in-memory database
Browse files Browse the repository at this point in the history
When another Rails instance is started by Capybara, it sets up a new
connection to the test database instead of re-using our in-memory DB.

http://www.spacevatican.org/2012/8/18/threading-the-rat/
  • Loading branch information
sunaku committed Dec 2, 2013
1 parent ac9b154 commit 1499cfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -172,6 +172,10 @@ database adapter][memory_test_fix]. Otherwise, you *might* face these errors:
> cannot start a transaction within a transaction
For older Rails, to use SQLite3 as your test database along with browser-based
acceptance testing frameworks such as Capybara, see
http://www.spacevatican.org/2012/8/18/threading-the-rat/

## Configuration

Tork looks for a configuration directory named `.tork/` inside its working
Expand Down
8 changes: 8 additions & 0 deletions lib/tork/config/rails/master.rb
Expand Up @@ -31,6 +31,14 @@ class Tork::Railtie < Rails::Railtie
if File.exist? seeds = "#{Rails.root}/db/seeds.rb"
load seeds
end

# keep sub-Rails connected to in-memory database
# e.g. when another Rails is started by Capybara
# http://www.spacevatican.org/2012/8/18/threading-the-rat/
class << ActiveRecord::Base
memory_database_connection = ActiveRecord::Base.connection
define_method(:connection) { memory_database_connection }
end
end
end
end
Expand Down

0 comments on commit 1499cfa

Please sign in to comment.