Permalink
Browse files

make all features pass

  • Loading branch information...
1 parent e1b7a96 commit cbcfd88dc983340281db20915a80e3831c8f6950 @aslakhellesoy aslakhellesoy committed May 23, 2011
@@ -1,3 +1,4 @@
+require 'cucumber/rails/hooks/active_record'
require 'cucumber/rails/hooks/database_cleaner'
require 'cucumber/rails/hooks/allow_rescue'
require 'cucumber/rails/hooks/mail'
@@ -0,0 +1,14 @@
+if defined?(ActiveRecord::Base)
+ require 'cucumber/rails3/active_record'
+
+ Before('@javascript') do
+ # 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
+ end
+
+ Before('~@javascript') do
+ # Do not use a shared connection unless we're in a @javascript scenario
+ ActiveRecord::Base.shared_connection = nil
+ end
+end
@@ -6,7 +6,6 @@
if defined?(ActiveRecord::Base)
require 'rails/test_help'
- require 'cucumber/rails3/active_record'
else
require 'action_dispatch/testing/test_process'
require 'action_dispatch/testing/integration'
@@ -6,7 +6,3 @@ 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

2 comments on commit cbcfd88

@bwbuchanan

Database connection adapter instances are not threadsafe! I just spent literally all night trying to track down some incredibly strange failures in my @javascript scenarios, which turned out to be caused by multiple threads performing queries on the same PGconn object simultaneously, resulting in one of the queries randomly failing or the result from one thread being delivered to the other thread, causing Rails to get very, very confused.

This change needs to be reverted ASAP.

@aslakhellesoy
Member

Pleas create a ticket so we remember to fix this!

Please sign in to comment.