DEV: Remove use of cd in the app (#8337)

`FileUtils.cd` and `Dir.chdir` cause the working directory to change for the entire process. We run sidekiq jobs, hijacked requests and deferred jobs in threads, which can make working directory changes have unintended side-effects.

- Add a rubocop rule to warn about usage of Dir.chdir and FileUtils.cd
- Added rubocop:disable for scripts used outside the app
- Refactored code using cd to use alternative methods
- Temporarily skipped the rubocop check for lib/backup_restore. This will require more complex refactoring, so I will create a separate PR for review
This commit is contained in:
David Taylor
2019-11-13 09:57:39 +00:00
committed by GitHub
parent e4df3792f6
commit 9fea43e46a
7 changed files with 86 additions and 55 deletions

View File

@ -32,7 +32,7 @@ module Autospec
end
# launch rspec
Dir.chdir(Rails.root) do
Dir.chdir(Rails.root) do # rubocop:disable DiscourseCops/NoChdir because this is not part of the app
env = { "RAILS_ENV" => "test" }
if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ }
env["LOAD_PLUGINS"] = "1"