Skip to content

Instantly share code, notes, and snippets.

@lujanfernaud
Last active December 28, 2023 17:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lujanfernaud/67644f8ea4263f4e638be1090ec85580 to your computer and use it in GitHub Desktop.
Save lujanfernaud/67644f8ea4263f4e638be1090ec85580 to your computer and use it in GitHub Desktop.
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