Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minitest and Database Cleaner

Minitest and Database Cleaner

test_helper.rb

require 'database_cleaner'
require 'database_cleaner_support'

DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :transaction

class ActionDispatch::IntegrationTest
  # ...

  include DatabaseCleanerSupport
  
  # ...
end

class ActiveSupport::TestCase
  # ...

  include DatabaseCleanerSupport

  # ...
end

database_cleaner_support.rb

# frozen_string_literal: true

module DatabaseCleanerSupport
  def before_setup
    super
    DatabaseCleaner.start
  end

  def after_teardown
    DatabaseCleaner.clean
    super
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.