-
-
Save bullshit/10011491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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