5

We have a project that is using the AR-Octopus gem using sharded databases. The problem we are running into is that the gem 'database_cleaner' is not cleaning records when using this setup, as we are consistently having leftover records in our test database that cause issues with our test suite.

I found this GitHub gist - https://gist.github.com/nowlinuxing/22ea0ab673a5622eb48d

Here is my database_cleaner config file

# spec/support/database_cleaner.rb

require 'database_cleaner'

RSpec.configure do |config|
  config.before(:suite) do
   DatabaseCleaner.strategy = :transaction
   DatabaseCleaner.clean_with(:truncation)
  end

  ["master", *Octopus.config[Rails.env].keys].each do |shard|
    DatabaseCleaner[:active_record, model: ActiveRecord::Base.using(shard)]
  end

  config.around(:each) do |example|
   DatabaseCleaner.cleaning do
    example.run
   end
  end
 end

Has anyone ever encountered this issue? If so, what did you do to resolve the issue? Just looking for some helpful insight.

William Holt
  • 549
  • 4
  • 14

0 Answers0