Skip to content

Commit

Permalink
Ensures headless JS server and testing environment are connecting to …
Browse files Browse the repository at this point in the history
…same database
  • Loading branch information
oponder committed Mar 12, 2013
1 parent 47e6f19 commit 911570a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 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

0 comments on commit 911570a

Please sign in to comment.