Skip to content

Rails を 8.0 系にアップグレード#353

Merged
nay merged 9 commits into
dev_4_0_2from
upgrade/rails-8.0
May 22, 2026
Merged

Rails を 8.0 系にアップグレード#353
nay merged 9 commits into
dev_4_0_2from
upgrade/rails-8.0

Conversation

@nay
Copy link
Copy Markdown
Owner

@nay nay commented May 18, 2026

概要

Rails を 7.2.3.1 → 8.0.5 へアップグレードし、config.load_defaults も 7.1 → 8.0 に切替えて Rails 8.0 のフレームワークデフォルトを全面適用します。gem 'rails', '~> 8.0.0' で 8.0.x 系に固定(8.1 系は除外)。

やったこと

gem アップグレード

  • アプリの挙動を変えずにフレームワークだけ上げたい: Gemfile の制約を ~> 8.0.0 に変更し bundle update rails で解決。コード修正なしで全テスト通過。変更は Gemfile / Gemfile.lock のみで、推移的依存(zeitwerk, rack, minitest, nokogiri 等)も更新。sassc-rails / rails-observers / activerecord-session_store / bootstrap-sass は無変更で Rails 8 互換。Ruby 3.4.9 / Bundler 2.6.9 は維持。

8.0 デフォルトの段階適用

  • デフォルトが変わる項目を一括 ON にすると挙動変化の切り分けが難しい: 7.2/8.0 で変わる7項目を 1 設定 = 1 コミットで config/application.rb に明示記述し、各コミットで全テストを実行して安全を確認しながら導入。
  • 全項目を個別検証後に load_defaults を切替え: 全7項目が個別検証済みになったため、config.load_defaults を 7.1 → 8.0 に切替えると同時に冗長化した明示設定を削除。belongs_to_required_by_default 等のバージョンデフォルトに依らない既存オーバーライドはそのまま残す。

適用された 8.0 デフォルト(7項目)

7.2 由来:

  • config.yjit = true(Ruby YJIT 有効化・性能向上)
  • config.active_record.validate_migration_timestamps = true(マイグレーションのタイムスタンプ検証)
  • config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp]
  • config.active_record.postgresql_adapter_decode_dates = true(PG の date 列を Date で返す)

8.0 由来:

  • config.active_support.to_time_preserves_timezone = :zoneto_time が完全な TZ を保持。Rails 8.1 の非推奨対応も兼ねる)
  • config.action_dispatch.strict_freshness = true(条件付きGETで RFC 7232 に従い ETag を優先)
  • Regexp.timeout = 1(ReDoS 対策のグローバル正規表現タイムアウト)

動作確認

  • 各コミットで RSpec 全 426 examples / 0 failures(pending 1 件は元から xit 指定の意図的スキップで本変更とは無関係)
  • 起動時の to_time 非推奨警告も解消

@nay nay force-pushed the upgrade/rails-8.0 branch from dbfd11c to a8e7fe7 Compare May 22, 2026 00:09
@nay nay marked this pull request as ready for review May 22, 2026 00:43
@nay nay merged commit 76476fe into dev_4_0_2 May 22, 2026
4 checks passed
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.

1 participant