Skip to content
Browse files

Allow transactional database strategy with Selenium.

  • Loading branch information...
1 parent 84104e6 commit 0572d3a04e39ff5633a5f507315359363612cd80 @parndt parndt committed Jul 7, 2012
Showing with 20 additions and 4 deletions.
  1. +14 −4 core/spec/support/database_cleaner.rb
  2. +6 −0 spec/spec_helper_no_rails.rb
View
18 core/spec/support/database_cleaner.rb
@@ -12,10 +12,20 @@
config.after(:each) do
DatabaseCleaner.clean
end
+end
- config.around(:each, :js) do |example|
- DatabaseCleaner.strategy = :truncation
- example.call
- DatabaseCleaner.strategy = :transaction
+# Allows transactional DatabaseCleaner strategy with Selenium.
+module ActiveRecord
+ class Base
+ mattr_accessor :shared_connection
+ @@shared_connection = nil
+
+ def self.connection
+ @@shared_connection || retrieve_connection
+ end
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
View
6 spec/spec_helper_no_rails.rb
@@ -0,0 +1,6 @@
+ENV['RAILS_ENV'] ||= 'TEST'
+require 'active_support'
+EXTENSIONS = %w[authentication core dashboard images pages resources]
+Dir[File.expand_path("../{#{EXTENSIONS.join(',')}}/app/models", __FILE__)].each do |model_dir|
+ $:.push File.expand_path('../../app/models/', __FILE__)
+end

0 comments on commit 0572d3a

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