Skip to content

Commit

Permalink
Upgrade to generating Rails 7.2 apps
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinkelly committed Aug 31, 2024
1 parent 851aeae commit 1bffe44
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ci/bin/build-and-test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def ensure_everything_is_committed
end

def build_rails_version_specifier(target_versions_path)
major_minor = YAML.safe_load(File.read(target_versions_path)).fetch("target_rails_major_minor")
major_minor = YAML.safe_load_file(target_versions_path).fetch("target_rails_major_minor")

"~> #{major_minor}.0"
end
Expand Down
4 changes: 2 additions & 2 deletions target_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This is stored in a separate file so we can share it between the template and
# our CI configuration.
target_rails_major_minor: '7.1' # specify as major.minor
target_rails_major_minor: '7.2' # specify as major.minor

# Set this to the minimum version of Ruby that the chosen Rails version supports.
minimum_ruby_major_minor: '2.7'
minimum_ruby_major_minor: '3.1'
12 changes: 6 additions & 6 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Config

def initialize
config_file_path = File.absolute_path(ENV.fetch("CONFIG_PATH", DEFAULT_CONFIG_PATH))
@yaml_config = YAML.safe_load(File.read(config_file_path))
@yaml_config = YAML.safe_load_file(config_file_path)
@acceptable_rails_versions_specifier = load_acceptable_rails_versions_specifier
end

Expand Down Expand Up @@ -181,7 +181,7 @@ def apply_template! # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Met
]
run_with_clean_bundler_env "bundle binstubs #{binstubs.join(" ")} --force"

template "variants/backend-base/rubocop.yml.tt", ".rubocop.yml"
template "variants/backend-base/rubocop.yml.tt", ".rubocop.yml", force: true
run_rubocop_autocorrections

cleanup_package_json
Expand Down Expand Up @@ -262,8 +262,8 @@ def build_engines_field
}
end

def update_package_json(&block)
package_json = JSON.load_file("./package.json").tap(&block)
def update_package_json(&)
package_json = JSON.load_file("./package.json").tap(&)

File.write("./package.json", "#{JSON.pretty_generate(package_json)}\n")
end
Expand Down Expand Up @@ -399,10 +399,10 @@ def create_initial_migration
run_with_clean_bundler_env "bin/rake db:migrate"
end

def gsub_file!(path, flag, *args, &block)
def gsub_file!(path, flag, ...)
content = File.binread(path)

gsub_file(path, flag, *args, &block)
gsub_file(path, flag, ...)

raise StandardError, "the contents of #{path} did not change!" if content == File.binread(path)
end
Expand Down
6 changes: 3 additions & 3 deletions variants/audit-logging/services/audit_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def self.log_example_event(current_user:, remote_ip:, phase_of_moon:, timestamp:
new(
type: EXAMPLE_LABEL,
context: {
remote_ip: remote_ip,
remote_ip:,
user_id: current_user.id,
phase_of_moon: phase_of_moon
phase_of_moon:
},
timestamp: timestamp
timestamp:
).send_to_log
end

Expand Down
4 changes: 2 additions & 2 deletions variants/audit-logging/spec/services/audit_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
it "logs the expected line to the Rails log" do
described_class.log_example_event(
current_user: user,
remote_ip: remote_ip,
phase_of_moon: phase_of_moon,
remote_ip:,
phase_of_moon:,
timestamp: timestamp_in_app_tz
)

Expand Down
10 changes: 10 additions & 0 deletions variants/backend-base/app/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@
gsub_file! "app/mailers/application_mailer.rb",
/default from: ['"]from@example\.com['"]/,
"default from: Rails.application.config.app.mail_from"

gsub_file!(
"app/controllers/application_controller.rb",
"allow_browser versions: :modern",
<<~AFTER
# As of Sept 2024, This includes Safari 17.2+, Chrome 120+, Firefox 121+,
# Opera 106+ which is too aggressive for us.
# allow_browser versions: :modern
AFTER
)
8 changes: 4 additions & 4 deletions variants/backend-base/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ rescue LoadError
# If highline is missing, we'll gracefully omit ansi color output
end

def within_project_root(&block)
Dir.chdir(File.expand_path("..", __dir__), &block)
def within_project_root(&)
Dir.chdir(File.expand_path("..", __dir__), &)
end

def test(opts)
Expand All @@ -46,10 +46,10 @@ def run(command)
end
end

def with_clean_bundler_env(&block)
def with_clean_bundler_env(&)
return yield unless defined?(Bundler)

Bundler.with_original_env(&block)
Bundler.with_original_env(&)
end

def copy(example_path)
Expand Down
4 changes: 2 additions & 2 deletions variants/backend-base/config/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
copy_file "variants/backend-base/config/initializers/sentry.rb", "config/initializers/sentry.rb"

gsub_file! "config/initializers/filter_parameter_logging.rb",
/ {2}:passw, :secret, /,
" :passw, :secret, :session, :cookie, :csrf, "
/:ssn/,
":ssn, :session, :cookie, :csrf"

apply "variants/backend-base/config/environments/development.rb"
apply "variants/backend-base/config/environments/production.rb"
Expand Down
4 changes: 2 additions & 2 deletions variants/backend-base/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand All @@ -47,7 +47,7 @@
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

Capybara::Selenium::Driver.new app, browser: :chrome, options: options
Capybara::Selenium::Driver.new app, browser: :chrome, options:
end

RSpec.configure do |config|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe "Session cookies are expired immediately after logout" do
let(:password) { SecureRandom.hex(16) }

let(:user) { FactoryBot.create(:user, password: password) }
let(:user) { FactoryBot.create(:user, password:) }

it "session cookies are invalidated by logging out" do
# Sign in
Expand Down
2 changes: 1 addition & 1 deletion variants/devise/spec/system/user_sign_in_feature_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe "User sign-in" do
let(:user) { FactoryBot.create(:user, email: email, password: password) }
let(:user) { FactoryBot.create(:user, email:, password:) }
let(:password) { "aaaabbbbccccdddd" }
let(:email) { "[email protected]" }

Expand Down
2 changes: 1 addition & 1 deletion variants/github_actions_ci/template.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
template "variants/github_actions_ci/workflows/ci.yml.tt", ".github/workflows/ci.yml"
template "variants/github_actions_ci/workflows/ci.yml.tt", ".github/workflows/ci.yml", force: true
copy_file "variants/github_actions_ci/workflows/deploy_to_ec2.yml", ".github/workflows/deploy_to_ec2.yml"
copy_file "variants/github_actions_ci/workflows/deploy_to_heroku.yml", ".github/workflows/deploy_to_heroku.yml"

Expand Down

0 comments on commit 1bffe44

Please sign in to comment.