Created
May 23, 2023 22:46
-
-
Save phallstrom/f0faf5b7c3733fa527f50723528f6de2 to your computer and use it in GitHub Desktop.
spec/support/database_cleaner.rb
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
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
# The README for DatabaseCleaner suggests this should be simpler, but it | |
# doesn't work using their examples. This does however, so don't touch it :-) | |
config.around(:each) do |example| | |
if example.metadata[:truncation] | |
DatabaseCleaner.strategy = :truncation | |
DatabaseCleaner.start | |
example.run | |
DatabaseCleaner.clean | |
else | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.cleaning do | |
example.run | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment