Skip to content

Commit 90bf74a

Browse files
committed
Rails 7.2 app:update
1 parent dade0f6 commit 90bf74a

File tree

17 files changed

+314
-130
lines changed

17 files changed

+314
-130
lines changed

bin/rubocop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env ruby
2+
require "rubygems"
3+
require "bundler/setup"
4+
5+
# explicit rubocop config increases performance slightly while avoiding config confusion.
6+
ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))
7+
8+
load Gem.bin_path("rubocop", "rubocop")

bin/setup

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
#!/usr/bin/env ruby
22
require "fileutils"
33

4-
# path to your application root.
5-
APP_ROOT = File.expand_path('..', __dir__)
4+
APP_ROOT = File.expand_path("..", __dir__)
5+
APP_NAME = "planner"
66

77
def system!(*args)
8-
system(*args) || abort("\n== Command #{args} failed ==")
8+
system(*args, exception: true)
99
end
1010

1111
FileUtils.chdir APP_ROOT do
1212
# This script is a way to set up or update your development environment automatically.
1313
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
1414
# Add necessary setup steps to this file.
1515

16-
puts '== Installing dependencies =='
17-
system! 'gem install bundler --conservative'
18-
system('bundle check') || system!('bundle install')
16+
puts "== Installing dependencies =="
17+
system! "gem install bundler --conservative"
18+
system("bundle check") || system!("bundle install")
1919

2020
# puts "\n== Copying sample files =="
21-
# unless File.exist?('config/database.yml')
22-
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
21+
# unless File.exist?("config/database.yml")
22+
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
2323
# end
2424

2525
puts "\n== Preparing database =="
26-
system! 'bin/rails db:prepare'
26+
system! "bin/rails db:prepare"
2727

2828
puts "\n== Removing old logs and tempfiles =="
29-
system! 'bin/rails log:clear tmp:clear'
29+
system! "bin/rails log:clear tmp:clear"
3030

3131
puts "\n== Restarting application server =="
32-
system! 'bin/rails restart'
32+
system! "bin/rails restart"
33+
34+
# puts "\n== Configuring puma-dev =="
35+
# system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}"
36+
# system "curl -Is https://#{APP_NAME}.test/up | head -n 1"
3337
end

config/application.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
require_relative "boot"
22

3-
require "rails"
4-
# Pick the frameworks you want:
5-
require "active_model/railtie"
6-
require "active_job/railtie"
7-
require "active_record/railtie"
8-
require "active_storage/engine"
9-
require "action_controller/railtie"
10-
require "action_mailer/railtie"
11-
require "action_mailbox/engine"
12-
require "action_text/engine"
13-
require "action_view/railtie"
14-
require "action_cable/engine"
3+
require "rails/all"
154
require "sprockets/railtie"
16-
require "rails/test_unit/railtie"
175

186
# Require the gems listed in Gemfile, including any gems
197
# you've limited to :test, :development, or :production.

config/cable.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
development:
2+
adapter: async
3+
4+
test:
5+
adapter: test
6+
7+
production:
8+
adapter: redis
9+
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10+
channel_prefix: planner_production

config/environments/development.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Show full error reports.
1515
config.consider_all_requests_local = true
1616

17-
# Enable server timing
17+
# Enable server timing.
1818
config.server_timing = true
1919

2020
# Enable/disable caching. By default caching is disabled.
@@ -24,9 +24,7 @@
2424
config.action_controller.enable_fragment_cache_logging = true
2525

2626
config.cache_store = :memory_store
27-
config.public_file_server.headers = {
28-
'Cache-Control' => "public, max-age=#{2.days.to_i}"
29-
}
27+
config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" }
3028
else
3129
config.action_controller.perform_caching = false
3230

@@ -39,8 +37,12 @@
3937
# Don't care if the mailer can't send.
4038
config.action_mailer.raise_delivery_errors = false
4139

40+
# Disable caching for Action Mailer templates even if Action Controller
41+
# caching is enabled.
4242
config.action_mailer.perform_caching = false
4343

44+
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
45+
4446
# Print deprecation notices to the Rails logger.
4547
config.active_support.deprecation = :log
4648

@@ -68,11 +70,14 @@
6870
# Annotate rendered view with file names.
6971
# config.action_view.annotate_rendered_view_with_filenames = true
7072

71-
# Raise error when a before_action's only/except options reference missing actions
73+
# Uncomment if you wish to allow Action Cable access from any origin.
74+
# config.action_cable.disable_request_forgery_protection = true
75+
76+
# Raise error when a before_action's only/except options reference missing actions.
7277
config.action_controller.raise_on_missing_callback_actions = true
7378

74-
# Required default host to link to!
75-
config.action_mailer.default_url_options = { host: 'localhost:3000' }
79+
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
80+
# config.generators.apply_rubocop_autocorrect_after_generate!
7681

7782
logger = ActiveSupport::Logger.new(STDOUT)
7883
logger.formatter = config.log_formatter

config/environments/production.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# config.require_master_key = true
2222

2323
# Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
24-
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24+
# config.public_file_server.enabled = false
2525

2626
# Compress CSS using a preprocessor.
2727
# config.assets.css_compressor = :sass
@@ -42,13 +42,21 @@
4242
# Store uploaded files on the local file system (see config/storage.yml for options).
4343
config.active_storage.service = :local
4444

45+
# Mount Action Cable outside main process or domain.
46+
# config.action_cable.mount_path = nil
47+
# config.action_cable.url = "wss://example.com/cable"
48+
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
49+
4550
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
4651
# Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
4752
# config.assume_ssl = true
4853

4954
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
5055
# config.force_ssl = true
5156

57+
# Skip http-to-https redirect for the default health check endpoint.
58+
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
59+
5260
# Log to STDOUT by default
5361
config.logger = ActiveSupport::Logger.new(STDOUT)
5462
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
@@ -67,8 +75,10 @@
6775

6876
# Use a real queuing backend for Active Job (and separate queues per environment).
6977
# config.active_job.queue_adapter = :resque
70-
# config.active_job.queue_name_prefix = "planner_#{Rails.env}"
78+
# config.active_job.queue_name_prefix = "planner_production"
7179

80+
# Disable caching for Action Mailer templates even if Action Controller
81+
# caching is enabled.
7282
config.action_mailer.perform_caching = false
7383

7484
# Ignore bad email addresses and do not raise email delivery errors.
@@ -85,6 +95,9 @@
8595
# Do not dump schema after migrations.
8696
config.active_record.dump_schema_after_migration = false
8797

98+
# Only use :id for inspections in production.
99+
config.active_record.attributes_for_inspect = [ :id ]
100+
88101
# Enable DNS rebinding protection and other `Host` header attacks.
89102
# config.hosts = [
90103
# "example.com", # Allow requests from example.com
@@ -105,4 +118,4 @@
105118
}
106119
ActionMailer::Base.delivery_method = :smtp
107120
config.action_mailer.default_url_options = { host: 'codebar.io' }
108-
end
121+
end

config/environments/test.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
config.eager_load = ENV["CI"].present?
2020

2121
# Configure public file server for tests with Cache-Control for performance.
22-
config.public_file_server.enabled = true
23-
config.public_file_server.headers = {
24-
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
25-
}
22+
config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" }
2623

2724
# Show full error reports and disable caching.
2825
config.consider_all_requests_local = true
26+
2927
config.action_controller.perform_caching = false
28+
3029
config.cache_store = :null_store
3130

3231
# Render exception templates for rescuable exceptions and raise for other exceptions.
@@ -38,13 +37,19 @@
3837
# Store uploaded files on the local file system in a temporary directory.
3938
config.active_storage.service = :test
4039

40+
# Disable caching for Action Mailer templates even if Action Controller
41+
# caching is enabled.
4142
config.action_mailer.perform_caching = false
4243

4344
# Tell Action Mailer not to deliver emails to the real world.
4445
# The :test delivery method accumulates sent emails in the
4546
# ActionMailer::Base.deliveries array.
4647
config.action_mailer.delivery_method = :test
4748

49+
# Unlike controllers, the mailer instance doesn't have any context about the
50+
# incoming request so you'll need to provide the :host parameter yourself.
51+
config.action_mailer.default_url_options = { host: "localhost:3000" }
52+
4853
# Print deprecation notices to the stderr.
4954
config.active_support.deprecation = :stderr
5055

@@ -60,11 +65,9 @@
6065
# Annotate rendered view with file names.
6166
# config.action_view.annotate_rendered_view_with_filenames = true
6267

63-
# Raise error when a before_action's only/except options reference missing actions
68+
# Raise error when a before_action's only/except options reference missing actions.
6469
config.action_controller.raise_on_missing_callback_actions = true
6570

66-
config.action_mailer.default_url_options = { host: 'localhost:3000' }
67-
6871
# Fake omniauth for testing
6972
OmniAuth.config.test_mode = true
7073

config/initializers/filter_parameter_logging.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# Use this to limit dissemination of sensitive information.
55
# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
66
Rails.application.config.filter_parameters += [
7-
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
7+
:passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
88
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Be sure to restart your server when you modify this file.
2+
#
3+
# This file eases your Rails 7.2 framework defaults upgrade.
4+
#
5+
# Uncomment each configuration one by one to switch to the new default.
6+
# Once your application is ready to run with all new defaults, you can remove
7+
# this file and set the `config.load_defaults` to `7.2`.
8+
#
9+
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
10+
# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
11+
12+
###
13+
# Controls whether Active Job's `#perform_later` and similar methods automatically defer
14+
# the job queuing to after the current Active Record transaction is committed.
15+
#
16+
# Example:
17+
# Topic.transaction do
18+
# topic = Topic.create(...)
19+
# NewTopicNotificationJob.perform_later(topic)
20+
# end
21+
#
22+
# In this example, if the configuration is set to `:never`, the job will
23+
# be enqueued immediately, even though the `Topic` hasn't been committed yet.
24+
# Because of this, if the job is picked up almost immediately, or if the
25+
# transaction doesn't succeed for some reason, the job will fail to find this
26+
# topic in the database.
27+
#
28+
# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter
29+
# will define the behaviour.
30+
#
31+
# Note: Active Job backends can disable this feature. This is generally done by
32+
# backends that use the same database as Active Record as a queue, hence they
33+
# don't need this feature.
34+
#++
35+
# Rails.application.config.active_job.enqueue_after_transaction_commit = :default
36+
37+
###
38+
# Adds image/webp to the list of content types Active Storage considers as an image
39+
# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png.
40+
# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support
41+
# WebP. Requires imagemagick/libvips built with WebP support.
42+
#++
43+
# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp]
44+
45+
###
46+
# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError
47+
# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp
48+
# associated with the current time. This is done to prevent forward-dating of migration files, which can
49+
# impact migration generation and other migration commands.
50+
#
51+
# Applications with existing timestamped migrations that do not adhere to the
52+
# expected format can disable validation by setting this config to `false`.
53+
#++
54+
# Rails.application.config.active_record.validate_migration_timestamps = true
55+
56+
###
57+
# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries.
58+
#
59+
# Example:
60+
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date
61+
#
62+
# This query used to return a `String`.
63+
#++
64+
# Rails.application.config.active_record.postgresql_adapter_decode_dates = true
65+
66+
###
67+
# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are
68+
# deploying to a memory constrained environment you may want to set this to `false`.
69+
#++
70+
# Rails.application.config.yjit = true

0 commit comments

Comments
 (0)