Skip to content

Commit 911570a

Browse files
committed
Ensures headless JS server and testing environment are connecting to same database
1 parent 47e6f19 commit 911570a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

spec/support/shared_db_connection.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class ActiveRecord::Base
2+
mattr_accessor :shared_connection
3+
@@shared_connection = nil
4+
5+
def self.connection
6+
@@shared_connection || retrieve_connection
7+
end
8+
end
9+
10+
# Forces all threads to share the same connection. This works on
11+
# Capybara because it starts the web server in a thread.
12+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
13+
14+
if Rails.env.javascript_test?
15+
module ActiveRecord
16+
module ConnectionAdapters
17+
module QueryCache
18+
private
19+
def cache_sql(sql,binds)
20+
yield
21+
end
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)