db_cleaner.rb 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
require 'database_cleaner/active_record/deletion'

module FakeInformationSchema
  # Work around a bug in DatabaseCleaner when using the deletion strategy:
  # https://github.com/DatabaseCleaner/database_cleaner/issues/347
  #
  # On MySQL, if the information schema is said to exist, we use an inaccurate
  # row count leading to some tables not being cleaned when they should
  def information_schema_exists?(_connection)
    false
  end
end

DatabaseCleaner::ActiveRecord::Deletion.prepend(FakeInformationSchema)

16
RSpec.configure do |config|
17
  # Ensure all sequences are reset at the start of the suite run
18 19 20
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end
21

22
  config.append_after(:context) do
23
    DatabaseCleaner.clean_with(:deletion, cache_tables: false)
24 25
  end

26
  config.before do
27 28 29
    DatabaseCleaner.strategy = :transaction
  end

30
  config.before(:each, :js) do
31
    DatabaseCleaner.strategy = :deletion, { cache_tables: false }
32 33
  end

34
  config.before(:each, :delete) do
35
    DatabaseCleaner.strategy = :deletion, { cache_tables: false }
36 37
  end

38
  config.before(:each, :migration) do
39
    DatabaseCleaner.strategy = :deletion, { cache_tables: false }
40 41
  end

42
  config.before do
43 44 45
    DatabaseCleaner.start
  end

46
  config.append_after do
47
    DatabaseCleaner.clean
48 49
  end
end