Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensures headless JS server and testing environment are connecting to …
…same database
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |