diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index dad9c5faf..8aa076438 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,6 +1,5 @@ RSpec.configure do |config| - - # database cleaner warning if you turn this off + # a warning if you turn this off config.before(:suite) do if config.use_transactional_fixtures? raise(<<-MSG) @@ -17,26 +16,29 @@ RSpec.configure do |config| DatabaseCleaner.clean_with(:truncation) end + config.before(:each) do DatabaseCleaner.strategy = :transaction end - # config.before(:suite) do - # DatabaseCleaner.clean_with(:truncation) - # end - # config.before do - # DatabaseCleaner.strategy = :transaction - # end + config.before(:each, type: :feature) do + # :rack_test driver's Rack app under test shares database connection + # with the specs, so continue to use transaction strategy for speed. + driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test - # config.before(:each, js: true) do - # DatabaseCleaner.strategy = :truncation - # end + unless driver_shares_db_connection_with_specs + # Driver is probably for an external browser with an app + # under test that does *not* share a database connection with the + # specs, so use truncation strategy. + DatabaseCleaner.strategy = :truncation + end + end - # config.before do - # DatabaseCleaner.start - # end + config.before(:each) do + DatabaseCleaner.start + end - # config.after do - # DatabaseCleaner.clean - # end + config.append_after(:each) do + DatabaseCleaner.clean + end end