Enable config.active_record.belongs_to_required_by_default
#1698
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
以前 Rails 5.0 にアップグレードする過程の残タスクとして、以下の設定のデフォルト値 (
true
) を上書きしたままになっていたので、本 PR でデフォルト値に戻す PR です。false -> true
にしてますが、Rails 8.1 などにアップグレードする際にbin/rails app:update
を実行すると上記コードは削除される(=デフォルト値に戻る)ので、本 PR では実際には当該コードを削除する形で対応しています ✂️ ✅やること
config.active_record.belongs_to_required_by_default
をデフォルト値 (true
) にする» AI による修正サポート
bundle exec rspec
PR #1698 の内容に従い、テストを実行しました。
主な失敗内容:
ActiveRecord::RecordInvalid: バリデーションに失敗しました: Prefectureを入力してください
というエラーです。belongs_to :prefecture
の関連が必須(required)になったため、テストデータ作成時にprefecture
が正しく設定されていないことが原因です。背景:
config.active_record.belongs_to_required_by_default
のデフォルト値(true
)に戻したことで、belongs_to
関連が必須になりました。prefecture_id
などの外部キーがnilだとバリデーションエラーになります。次の対応案:
prefecture
またはprefecture_id
を必ずセットするよう修正する必要があります。もし該当箇所の修正を進めたい場合は、どのファイルから対応したいかご指示ください。もしくは、失敗しているテストの該当Factoryやspecファイルをリストアップすることも可能です。