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

fix: use a safer gsub_file and update/remove file gsubs that were no longer doing anything #533

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Feb 19, 2024

So it turns out that gsub_file does not actually check if it matched anything and so we have a few misc. changes silently not being applied due to changes in Rails 7.1.

This addresses that by switching us to use gsub_file! which reads the file into memory before it's gsub'd and then compares the results to make sure it actually changed.

I've opened rails/thor#874 to add this to Thor itself

Comment on lines -18 to -20
gsub_file "config/environments/development.rb",
"join('tmp', 'caching-dev.txt')",
'join("tmp/caching-dev.txt")'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is no longer matching because of the quotes, but Rubocop can automatically fix this anyway now

config.force_ssl = ENV.fetch("RAILS_FORCE_SSL", "true").downcase != "false"
RUBY
gsub_file! "config/environments/production.rb",
"config.force_ssl = true",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Rails 7.1 now ships with this just enabled, but I think it's worth us keeping an env variable for toggling it just in case

gsub_file "config/initializers/filter_parameter_logging.rb", /\[:password\]/ do
"%w[password secret session cookie csrf]"
end
gsub_file! "config/initializers/filter_parameter_logging.rb",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this relates to #529 - technically I've fixed this gsub so we're now adding to the existing values, but we still want to re-review our options

Comment on lines -1 to -3
gsub_file "config/environments/test.rb",
"config.eager_load = false",
"config.eager_load = defined?(SimpleCov).present?"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Rails 7.1 has changed this to ENV["CI"].present? rather than true

I don't think it's better to check if SimpleCov is defined but maybe I'm wrong?

@G-Rath G-Rath merged commit dd5b3e9 into main Mar 8, 2024
22 checks passed
@G-Rath G-Rath deleted the fix-gsub branch March 8, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants