database_cleaner-active_record icon indicating copy to clipboard operation
database_cleaner-active_record copied to clipboard

v2.2.1 can overwrite DatabaseCleaner.strategy

Open aalong-tr opened this issue 5 months ago • 0 comments

On v2.2.0 of this gem, this config worked fine in my app:

RSpec.configure do |config|
  # ...
  DatabaseCleaner.strategy = :truncation
end

After upgrading to v2.2.1, my strategy was getting overwritten and set to transaction. I only noticed this because that strategy has never worked properly with the Sqlite3 memory database I use for this library, which meant that the overwrite was causing some errors. I was able to restore the original behavior with:

RSpec.configure do |config|
  # ...

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end
end

My best guess is that https://github.com/fatkodima/database_cleaner-active_record/blob/63aec2d25d6cac1322df926689ec33daf491de0e/lib/database_cleaner/active_record.rb#L10 needs to be ||= instead of =, but I defer to the subject matter experts.

aalong-tr avatar Jul 18 '25 23:07 aalong-tr