Skip to content

Instantly share code, notes, and snippets.

@bullshit
Forked from andreypronin/spec_helper.rb
Created April 6, 2014 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullshit/10011491 to your computer and use it in GitHub Desktop.
Save bullshit/10011491 to your computer and use it in GitHub Desktop.
config.use_transactional_fixtures = false
config.before(:suite) do
# Do truncation once per suite to vacuum for Postgres
DatabaseCleaner.clean_with :truncation
# Normally do transactions-based cleanup
DatabaseCleaner.strategy = :transaction
end
config.around(:each) do |spec|
if spec.metadata[:js] || spec.metadata[:test_commit]
# JS => run with PhantomJS that doesn't share connections => can't use transactions
# deletion is often faster than truncation on Postgres - doesn't vacuum
# no need to 'start', clean_with is sufficient for deletion
# Devise Emails: devise-async sends confirmation on commit only! => can't use transactions
spec.run
DatabaseCleaner.clean_with :deletion
else
# No JS/Devise => run with Rack::Test => transactions are ok
DatabaseCleaner.start
spec.run
DatabaseCleaner.clean
# see https://github.com/bmabey/database_cleaner/issues/99
begin
ActiveRecord::Base.connection.send(:rollback_transaction_records, true)
rescue
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment