Skip to content

フォロー関係がない場合の通知設定変更で発生するエラーを修正 - #10548

Open
komagata wants to merge 1 commit into
mainfrom
fix-10534-change-watching
Open

komagata wants to merge 1 commit into
mainfrom
fix-10534-change-watching

Conversation

@komagata

@komagata komagata commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

概要

フォロー関係が存在しない状態で通知設定を変更すると、User#change_watching が nil.update を呼び出し、500エラーになる問題を修正します。

  • フォロー関係がない場合は更新せず、既存のコントローラーの分岐で400を返すようにしました。
  • 未フォロー時・フォロー解除後の回帰テストと、通常の通知設定変更が204を返すAPIテストを追加しました。
  • フォロー関係を新規作成せず、他ユーザーの通知設定に影響しないことも確認しています。

確認

  • モデル・APIテスト: 82 runs, 290 assertions, 0 failures, 0 errors
  • 変更した3ファイルのRuboCop: 指摘なし
  • git diff --check
  • 最新のmainとの競合なし

テストは分離した一時PostgreSQLデータベースで実行しました。

Closes #10534

Summary by CodeRabbit

  • バグ修正
    • フォロー中の相手に対する監視設定を、オン・オフに切り替えられるようになりました。
    • フォローしていない相手やフォロー解除済みの相手への監視設定変更は、エラーとして正しく処理されます。処理後もフォロー状態や他の相手の監視設定に影響しません。

Review App

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: fjordllc/bootcamp/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 329fa82f-92af-49b1-8981-7748ecda38df

📥 Commits

Reviewing files that changed from the base of the PR and between ade4d8e and 8fa3c22.

📒 Files selected for processing (3)
  • app/models/user.rb
  • test/controllers/api/followings_controller_test.rb
  • test/models/user_test.rb

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

User#change_watching は、対象ユーザーとの Following レコードがない場合に更新を行わないよう変更されました。モデルテストとAPIテストで、更新成功時の状態と未フォロー時の応答を確認します。

Changes

watch設定の更新

Layer / File(s) Summary
フォロー関係の確認と更新テスト
app/models/user.rb, test/models/user_test.rb, test/controllers/api/followings_controller_test.rb
Following レコードが存在するときだけwatchを更新します。モデルテストは監視設定の切り替えと、未フォローまたはフォロー解除後に更新が失敗することを確認します。APIテストは更新成功時の 204 No Content と、未フォローまたはフォロー解除後の 400 Bad Request を確認します。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: oyamairishitomi

Merge Risk: ⚪ Minimal · up to 8fa3c

The change appears ready for normal merge checks: watch updates without a follow relationship no longer attempt the missing-record update, and the API returns 400.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、フォロー関係がない場合に通知設定の変更で発生するエラーを修正する主要な変更を簡潔かつ明確に示しています。
Description check ✅ Passed 概要、変更内容、確認結果、テスト結果、関連Issueを記載しています。テンプレートの「Issue」「変更確認方法」「Screenshot」セクションはありませんが、主要な情報は十分に含まれています。
Linked Issues check ✅ Passed [#10534] User#change_watching は、対象の Following レコードがある場合だけ watch を更新します。レコードがない場合は nil.update を実行しません。モデルテストは未フォロー時とフォロー解除後に更新が失敗し、Following 件数が変わらないことを確認します。APIテストは両ケースで 400 Bad Request を確…
Out of Scope Changes check ✅ Passed 変更は User#change_watching の例外修正と、その回帰テストに限定されています。APIテストとモデルテストは、フォロー関係、他ユーザーの監視状態、フォロー件数への影響を検証するため、[#10534] の実装を直接支援します。無関係な変更は確認できません。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

NoMethodError: undefined method 'update' for nil

1 participant