Skip to content

Fix test helpers to restore original database connection#229

Merged
PNixx merged 1 commit intoPNixx:masterfrom
natevick:fix-test-helper-connection-restore
Jan 21, 2026
Merged

Fix test helpers to restore original database connection#229
PNixx merged 1 commit intoPNixx:masterfrom
natevick:fix-test-helper-connection-restore

Conversation

@natevick
Copy link
Copy Markdown
Contributor

@natevick natevick commented Jan 20, 2026

Summary

The minitest and rspec test helpers change ActiveRecord::Base.connection to ClickHouse but never restore it afterward. This breaks multi-database Rails apps where the primary database is PostgreSQL/MySQL.

Before: After before_setup (minitest) or before (rspec) runs, ActiveRecord::Base.connection points to ClickHouse instead of the app's primary database.

After: The original connection is saved before truncating ClickHouse tables and restored afterward.

Changes

  • lib/clickhouse-activerecord/minitest.rb: Save connection config before iterating ClickHouse configs, restore in ensure block
  • lib/clickhouse-activerecord/rspec.rb: Same fix, plus renamed block variable from config to db_config to avoid shadowing the outer RSpec.configure block variable

Test plan

  • Verify in a multi-database Rails app that ActiveRecord::Base.connection remains pointed at the primary database after test setup runs

🤖 Generated with Claude Code

The minitest and rspec helpers were changing ActiveRecord::Base.connection
to ClickHouse without restoring it afterward. This broke multi-database
Rails apps where the primary database is PostgreSQL/MySQL.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@PNixx PNixx merged commit 175c720 into PNixx:master Jan 21, 2026
25 checks passed
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.

2 participants