Skip to content

Restore the Active Record connection after building fixtures #99

Description

@nertzy

spec:fixture_builder:build establishes the test connection before loading the fixture builder:

ActiveRecord::Base.establish_connection(:test)

It does not restore the caller’s previous connection afterward. A later task in the same Rake process can therefore use the test database even while Rails.env still reports another environment.

This was reproduced on current master with separate development and test SQLite databases. Resetting Rails.env does not repair the connection leak.

  • Keep the test connection active while fixtures are being built.
  • Restore the caller’s previous connection after a successful build.
  • Restore it when fixture generation raises.
  • Add regression coverage that identifies the actual database used before, during, and after the build.

This preserves safe task composition without automatically modifying Rails’ standard db:fixtures:load task.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions