Problem Description
When running tests with bundle exec rspec, the tests appear to be destructive to the development database, requiring a database reset after each test run. This is an anti-pattern that significantly impacts developer productivity.
Expected Behavior
Tests should:
- Always use the test database (
vulcan_vue_test) regardless of how they're invoked
- Never affect the development database (
vulcan_vue_development)
- Not require a database reset after running tests
Current Behavior
- Running tests seems to affect the development database
- After running tests,
rails db:reset is needed to restore the development database
- Spring server and other processes hold database connections, making reset difficult
Investigation Needed
- Verify that
ENV['RAILS_ENV'] is properly set to 'test' when running specs
- Check if DatabaseCleaner is somehow affecting the wrong database
- Investigate if there's a configuration issue causing tests to connect to development database
- Review if any specs are explicitly changing
Rails.env or database connections
Configuration Details
- Rails 8.0.2.1
- Ruby 3.3.9
- PostgreSQL
- DatabaseCleaner configured with transaction/truncation strategies
- Separate databases configured in database.yml:
- Development:
vulcan_vue_development
- Test:
vulcan_vue_test
Potential Causes
- Missing or incorrect
ENV['RAILS_ENV'] = 'test' setting
- DatabaseCleaner misconfiguration
- Specs that manually connect to development database
- Spring or other preloaders interfering with environment detection
- Database URL environment variable overriding database.yml
Reproduction Steps
- Run
bundle exec rspec in development
- Try to use the application
- Notice data corruption or missing data
- Need to run
rails db:reset to fix
Workaround
Currently must explicitly set environment: RAILS_ENV=test bundle exec rspec
Priority
High - This significantly impacts developer experience and could lead to accidental data loss in development environments.
Problem Description
When running tests with
bundle exec rspec, the tests appear to be destructive to the development database, requiring a database reset after each test run. This is an anti-pattern that significantly impacts developer productivity.Expected Behavior
Tests should:
vulcan_vue_test) regardless of how they're invokedvulcan_vue_development)Current Behavior
rails db:resetis needed to restore the development databaseInvestigation Needed
ENV['RAILS_ENV']is properly set to 'test' when running specsRails.envor database connectionsConfiguration Details
vulcan_vue_developmentvulcan_vue_testPotential Causes
ENV['RAILS_ENV'] = 'test'settingReproduction Steps
bundle exec rspecin developmentrails db:resetto fixWorkaround
Currently must explicitly set environment:
RAILS_ENV=test bundle exec rspecPriority
High - This significantly impacts developer experience and could lead to accidental data loss in development environments.