From 911570ad1926420fcf329618a8d8b2ca87948e19 Mon Sep 17 00:00:00 2001 From: Oliver Ponder Date: Tue, 12 Mar 2013 01:23:16 +0100 Subject: [PATCH] Ensures headless JS server and testing environment are connecting to same database --- spec/support/shared_db_connection.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/support/shared_db_connection.rb diff --git a/spec/support/shared_db_connection.rb b/spec/support/shared_db_connection.rb new file mode 100644 index 00000000..1f4f13f3 --- /dev/null +++ b/spec/support/shared_db_connection.rb @@ -0,0 +1,25 @@ +class ActiveRecord::Base + mattr_accessor :shared_connection + @@shared_connection = nil + + def self.connection + @@shared_connection || retrieve_connection + end +end + +# Forces all threads to share the same connection. This works on +# Capybara because it starts the web server in a thread. +ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection + +if Rails.env.javascript_test? + module ActiveRecord + module ConnectionAdapters + module QueryCache + private + def cache_sql(sql,binds) + yield + end + end + end + end +end