diff --git a/README.md b/README.md index 8faac88..50f9e73 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/tork/config/rails/master.rb b/lib/tork/config/rails/master.rb index ff9af97..133edb6 100644 --- a/lib/tork/config/rails/master.rb +++ b/lib/tork/config/rails/master.rb @@ -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