Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make all features pass

  • Loading branch information...
commit cbcfd88dc983340281db20915a80e3831c8f6950 1 parent e1b7a96
@aslakhellesoy aslakhellesoy authored
View
1  lib/cucumber/rails/hooks.rb
@@ -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'
View
14 lib/cucumber/rails/hooks/active_record.rb
@@ -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
View
1  lib/cucumber/rails3.rb
@@ -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'
View
4 lib/cucumber/rails3/active_record.rb
@@ -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

Pleas create a ticket so we remember to fix this!

Please sign in to comment.
Something went wrong with that request. Please try again.