v2.2.1 can overwrite DatabaseCleaner.strategy

Open Beginner friendly
#126 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
ruby, sqlite
Domain
database, testing

Research direction

Read lib/database_cleaner/active_record.rb at the linked line, then reproduce the reported RSpec configuration with the SQLite3 memory database. Done means an explicitly configured DatabaseCleaner.strategy remains :truncation rather than being overwritten with :transaction.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Ruby
Stars
76
Forks
76
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DatabaseCleaner/database_cleaner-active_record

All issues in DatabaseCleaner/database_cleaner-active_record

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.