Skip to content

Fix nil strategy assignment for non-default databases - #731

Open
dajiaohuang wants to merge 1 commit into
DatabaseCleaner:mainfrom
dajiaohuang:fix/null-strategy-named-db-20261016
Open

dajiaohuang wants to merge 1 commit into
DatabaseCleaner:mainfrom
dajiaohuang:fix/null-strategy-named-db-20261016

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

The README documents strategy = nil as the way to select the no-op strategy. With a non-default database, that assignment instead raises ArgumentError:

cleaner = DatabaseCleaner[:active_record, db: :second_db]
cleaner.strategy = nil
# You must provide a strategy object that supports non default databases when you specify a database

This also prevents DatabaseCleaner.strategy = nil from disabling cleaning across a registry that includes named databases. The reproduction needs only database_cleaner-core; it does not open a database connection.

Change

Pass the strategy accessor result to set_strategy_db, so the existing nil-to-NullStrategy normalization runs before assigning the database. Keep the existing validation for custom strategies that do not support named databases.

Add regression coverage for the individual cleaner and the mixed default/named-database registry, including no-op block execution.

Validation

  • Original base plus the new tests: 89 examples, 2 failures (the new regressions).
  • Fixed core specs: 89 examples, 0 failures on Ruby 3.2.3, with an isolated RSpec bootstrap that omits Bundler/byebug setup.
  • Built and locally installed the core gem; exercised registry/strategy options, start/clean, block return and exception cleanup, one-shot clean_with, multiple databases, nil strategy and the Cucumber hook using in-memory strategies only.
  • Full Bundler/Cucumber suite was not run: it requires adapter dependencies and a Redis service. No real database or Redis endpoint was used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant