Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RAILS_ENV to test for test tasks #441

Closed

Conversation

etiennebarrie
Copy link

Rails had a hack that was removed in 7.0, this adds it back here.

Rails had a hack that was removed in 7.0, this adds it back here.
@bkeepers
Copy link
Owner

@etiennebarrie Do you have any more context on why this hack was removed from Rails 7? How does Rails currently handle switching environments for rake tasks?

@etiennebarrie
Copy link
Author

I removed it because I felt like it was bad form to change the environment when requiring a file and it wasn't necessary anymore since we were now using TestUnit::Runner (i.e. rails test) to run the tests which sets the environment to whatever is passed on the command line or test by default.

Also it was causing issues using Rails engines, which load all the dummy app's tasks under app:, which resulted in app:test not running in the test environment.

How does Rails currently handle switching environments for rake tasks?

There's no longer any specific code related to the environment for rake tasks as far as I know. If you happen to run one of the test tasks, they fork to rails test, and it changes the environment as previously mentioned (only for the fork).

@bkeepers
Copy link
Owner

Fixed this in #470.

I removed it because I felt like it was bad form to change the environment when requiring a file

Yeah, good call. I refactored this to not mutate the environment, but just return a different value internally for dotenv.

@bkeepers bkeepers closed this Jan 21, 2024
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.

None yet

2 participants