Skip to content

分報にメンション機能を追加#9308

Merged
komagata merged 9 commits intomainfrom
feature/send-notification-when-mentioned-in-micro-report
Feb 9, 2026
Merged

分報にメンション機能を追加#9308
komagata merged 9 commits intomainfrom
feature/send-notification-when-mentioned-in-micro-report

Conversation

@tyrrell-IH
Copy link
Copy Markdown
Contributor

@tyrrell-IH tyrrell-IH commented Nov 14, 2025

Issue

概要

分報の本文にて自分以外のユーザーにメンションした場合、メンションされたユーザーに通知が飛ぶように実装しました。
基本的な動作は日報やコメント等でメンションしたときと同様です。

分報機能ではmicro_reports#showに対するルーティング及び画面が用意されていません。
なので

  • 通知(notificationsテーブル)のlinkに該当の分報idをクエリとして保存する
    (例/users/{user_id}/micro_reports?micro_report_id={micro_report_id})
  • リクエストの都度該当の分報がどのページにあるか計算、クエリとして?page={page_number}を、フラグメントとして#micro_report_{micro_report_id}を付け、該当の分報まで遷移する

という実装にしています。

変更確認方法

  1. feature/send-notification-when-mentioned-in-micro-reportをローカルに取り込む。
git fetch origin feature/send-notification-when-mentioned-in-micro-report
git checkout feature/send-notification-when-mentioned-in-micro-report
  1. fixturesの追加があるのでbin/rails db:seedを実行する。
  2. ローカルサーバーを立ち上げる。
foreman start -f Procfile.dev


本PRもRuby on Rails8.0のmainをrebaseしたのでサーバーの立ち上げは

bin/dev

になります。

動作確認

通知が届くことの確認

  • ユーザーkimuraでログインしusers/{kimuraのuser_id}/micro_reportsへ移動する。
  • すでにテスト用の分報が25件登録されていることを確認し、新規の分報を
    @machida 削除予定です
    という内容で投稿する。
  • users/{kimuraのuser_id}/micro_reports2ページ目にメンション付きの分報が投稿されたことを確認する。
  • ユーザーmachidaでログインし、http://localhost:3000/notifications?status=unreadへ移動。
  • 「kimuraさんの分報でkimuraさんからメンションがきました」という未読の通知が届いていることを確認。
  • 未読の通知をクリックし、以下を確認する
    • 分報の2ページ目に遷移している(urlに?page=2のクエリが付いている)。
    • フラグメントにより該当の分報まで画面遷移している(urlに#micro_report_{id}のフラグメントが付いている)。

分報がどのページにあるか計算するロジックが正しく動作しているかの確認

  • ユーザーmachidaでログインした状態で、kimura所有の「テスト用の分報」を1件削除する。
  • http://localhost:3000/notificationsへアクセスする。
  • 先ほど開いた通知を再度クリックし、以下の内容を確認する。
    • 分報の1ページ目に遷移している(urlのクエリが?page=1に変更されている)。
    • フラグメントにより該当の分報まで画面遷移している(urlに#micro_report_{id}のフラグメントが付いている)。

通知のメッセージが「(分報所有者)の分報で(分報投稿者)さんからメンションがきました」の形式になっているかの確認

ユーザーmachidaでログインしたまま、ユーザーkimura所有の分報に@kimuraとメンションを入れて投稿。

  • ユーザーkimuraで再度ログインし、http://localhost:3000/notifications?status=unreadへ移動。
  • 「kimuraさんの分報でmachidaさんからメンションがきました」という未読の通知が届いていることを確認。

参考: メール通知は以下のようになります。
_development__LetterOpenerWeb

メンション付き分報が削除された場合に、通知も削除

  • ユーザーkimuraでログインした状態で、「通知が届くことの確認」で作成した「@machida 削除予定です」という内容の分報を削除する。
  • ユーザーmachidaでログイン、http://localhost:3000/notificationsへ移動する。
  • 「kimuraさんの分報でkimuraさんからメンションがきました」という通知が消えていることを確認する。

メンション付き分報が削除された場合の通知の削除について

日報の動作に倣って、メンション付き分報が削除された場合には通知も削除されるように実装しました。

参考: app/models/report_callbacks.rb


削除された分報のlinkを踏んでしまったら

分報のlinkを便宜的に/users/{user_id}/micro_reports?micro_report_id={micro_report_id}としてnotificationsテーブルに保存しています。

メンション付き分報が削除された場合には通知も削除されるので、上記linkも基本的に踏むことはないと考えていますが、もし何らかの理由で踏んでしまった場合には

  • 404の画面ではなく
ご指定のページが見つかりません
  • 「指定された分報は見つかりませんでした。」という警告メッセージとともに、micro_report#indexの画面を表示するように設定しています。
_development__machidaの分報一覧___FBC

Screenshot

変更前

変更前画像なし

変更後

メンションを送る

_development__kimuraの分報一覧___FBC

サイト内通知

_development__通知___FBC

メール通知

_development__LetterOpenerWeb

URL

_development__kimuraの分報一覧___FBC

Summary by CodeRabbit

  • 新機能

    • 分報のメンション文言を分報向けに調整。
  • 改善 / バグ修正

    • micro_report_id付きURLで該当ページへ自動遷移し、対象分報へアンカー移動。
    • 分報一覧を投稿日時の昇順で安定化、対象のページ算出に対応。
    • 分報削除時に関連するメンション通知をまとめて削除。
    • 無効なmicro_report_id指定時はインデックスへ戻り警告を表示。
    • メール内の送信者表示を分報側の送信者名に変更。
  • テスト

    • メンション通知、リンク遷移、並び順・ページ算出、通知削除を検証するテストを追加。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 14, 2025

📝 Walkthrough

Walkthrough

micro_reportにMentionerを組み込み、MicroReportにpath・senderエイリアス・削除コールバックを追加。Userに分報の順序取得と特定分報のページ算出を追加し、コントローラーはmicro_report_idで該当ページへアンカー付きリダイレクトするよう変更。テストとフィクスチャを追加。

Changes

Cohort / File(s) Change Summary
コントローラー(ページ遷移)
app/controllers/users/micro_reports_controller.rb
indexparams[:micro_report_id]を受け取り、該当MicroReportがあればUser#page_of_micro_reportでページ算出後に該当ページへアンカー(#micro_report_<id>)付きでリダイレクト。一覧取得を@user.ordered_micro_reportsへ変更。
モデル:MicroReport / Mentioner / コールバック
app/models/micro_report.rb, app/models/concerns/mentioner.rb, app/models/micro_report_callbacks.rb
MicroReportinclude Mentionermentionable_as :contentalias sender comment_userpathメソッド、after_destroy MicroReportCallbacks.newを追加。Mentioner.where_mentionにMicroReport向け分岐追加。MicroReportCallbacksで削除時にNotification.where(link: micro_report.path).destroy_allを実行。
モデル:User(ページ計算)
app/models/user.rb
ordered_micro_reports(created_at 昇順)とpage_of_micro_report(micro_report_id, per_page)(指定レコードのページ番号を計算)を追加。
ビュー/メール差替え
app/views/activity_mailer/mentioned.html.slim
メンション通知のタイトルで@mentionable.sender.login_nameを使用するよう変更(以前は@mentionable.user.login_name)。
テスト・サポート
test/models/micro_report_test.rb, test/models/user_test.rb, test/system/user/micro_reports_test.rb, test/system/notification/mention_test.rb, test/supports/notification_helper.rb
MicroReport#pathや削除時の通知削除、User#ordered_micro_reports/page_of_micro_reportの単体テスト、micro_report_idによるページ遷移・存在しないIDのアラートのシステムテスト、micro_reportからのメンション通知テストを追加。NotificationHelperに分報向けメッセージ生成のprivateメソッドを追加。
フィクスチャ更新
db/fixtures/micro_reports.yml
micro_report29のcomment_user追加と、ID 30〜54 のmicro_reportエントリをERBループで追加(user: kimura、content: "テスト用の分報")。

Sequence Diagram(s)

sequenceDiagram
    participant Browser as ブラウザ
    participant Controller as Users::MicroReportsController
    participant UserModel as User
    participant Router as Rails Redirect
    Browser->>Controller: GET /users/:id/micro_reports?micro_report_id=:id
    Controller->>UserModel: page_of_micro_report(micro_report_id, PAGER_NUMBER)
    UserModel-->>Controller: page number or nil
    alt found
        Controller->>Router: redirect to /users/:id/micro_reports?page=N#micro_report_<id>
        Router-->>Browser: 302 Redirect
    else not found
        Controller-->>Browser: redirect to index with alert
    end
Loading
sequenceDiagram
    participant App as Application
    participant MicroReport as MicroReport
    participant Callbacks as MicroReportCallbacks
    participant Notification as Notification DB
    App->>MicroReport: destroy
    MicroReport->>Callbacks: after_destroy(micro_report)
    Callbacks->>Notification: where(link: micro_report.path).destroy_all
    Notification-->>Callbacks: destroyed records
    Callbacks-->>App: callback complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • kutimiti1234
  • komagata

Poem

分報でぴょんと呼ぶよ、🐰
ページ跳んで君のところへ、
アンカーで見つけてぴたっと止まり、
消えた通知も追いかけて、
小さなメッセージ、届けるよ。

🚥 Pre-merge checks | ✅ 2 | ❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトル「分報にメンション機能を追加」は、変更内容の主要な目的(分報へのメンション機能追加)を簡潔かつ明確に説明しており、変更セット全体を正確に要約しています。
Description check ✅ Passed PRの説明は必要なセクションを含み、課題のリンク、変更概要、詳細な動作確認手順、スクリーンショットが記載されている。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/send-notification-when-mentioned-in-micro-report

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 and usage tips.

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 156cc26 to d631aea Compare November 25, 2025 07:11
@tyrrell-IH tyrrell-IH self-assigned this Nov 25, 2025
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from d631aea to 906e747 Compare November 27, 2025 01:39
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch 4 times, most recently from d285b98 to d31acce Compare December 15, 2025 04:08
@tyrrell-IH tyrrell-IH marked this pull request as ready for review December 15, 2025 04:11
@github-actions github-actions Bot requested a review from komagata December 15, 2025 04:11
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/controllers/users/micro_reports_controller.rb (1)

11-18: 特定の分報へのリダイレクト機能が適切に実装されています。

micro_report_idパラメータが指定された場合に、対象の分報が含まれるページへリダイレクトする機能が正しく実装されています。ordered_micro_reportsの使用により、コードの可読性と保守性が向上しています。

Line 13のpage_of_micro_reportの戻り値は理論上nilになる可能性があります。実際にはLine 12のfindが成功すれば常にページ番号が返されるはずですが、より防御的なコードにするため、以下のようなnil チェックを検討してもよいでしょう:

     if params[:micro_report_id].present?
       micro_report = @user.micro_reports.find(params[:micro_report_id])
       page = @user.page_of_micro_report(params[:micro_report_id].to_i, PAGER_NUMBER)
+      page ||= FIRST_PAGE

       return redirect_to user_micro_reports_path(@user, page:, anchor: "micro_report_#{micro_report.id}")
     end

ただし、現状の実装でも実用上問題はなく、テストでカバーされているため、この変更は任意です。

app/models/micro_report.rb (1)

13-18: MicroReport#path の設計は要件と合っており妥当です(将来的な共通化案は任意)

分報には個別の show ページがなく、ユーザーの分報一覧に micro_report_id パラメータ付きで遷移する設計なので、この user_micro_reports_path(user, micro_report_id: id) を返す実装は要件と噛み合っていると思います。
将来的に他の mentionable モデルでも似たような URL 生成が増えてきたら、ルーティングヘルパを使う path 実装を Concern などに共通化してもよさそうですが、現状のままでも十分シンプルで読みやすいです。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b4aefe and d31acce.

📒 Files selected for processing (9)
  • app/controllers/users/micro_reports_controller.rb (1 hunks)
  • app/models/concerns/mentioner.rb (1 hunks)
  • app/models/micro_report.rb (1 hunks)
  • app/models/user.rb (1 hunks)
  • db/fixtures/micro_reports.yml (1 hunks)
  • test/models/micro_report_test.rb (1 hunks)
  • test/models/user_test.rb (1 hunks)
  • test/system/notification/mention_test.rb (1 hunks)
  • test/system/user/micro_reports_test.rb (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
db/**

📄 CodeRabbit inference engine (AGENTS.md)

Database migrations and schema should be stored in db/ directory; app-specific utilities in lib/; static assets in public/

Files:

  • db/fixtures/micro_reports.yml
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/concerns/mentioner.rb
  • app/models/user.rb
  • app/models/micro_report.rb
  • app/controllers/users/micro_reports_controller.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/models/concerns/mentioner.rb
  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • app/models/user.rb
  • app/models/micro_report.rb
  • test/system/user/micro_reports_test.rb
  • app/controllers/users/micro_reports_controller.rb
  • test/system/notification/mention_test.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/concerns/mentioner.rb
  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • app/models/user.rb
  • app/models/micro_report.rb
  • test/system/user/micro_reports_test.rb
  • app/controllers/users/micro_reports_controller.rb
  • test/system/notification/mention_test.rb
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*_test.rb: Test suite should use Minitest with structure: system/, models/, controllers/, and fixtures in test/fixtures/; test files should be named *_test.rb
Use Minitest + Capybara for system tests; place unit and integration tests under matching test/* directories

Files:

  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
test/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep tests deterministic and use fixtures stored in test/fixtures/ for test data

Files:

  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
test/**/*

⚙️ CodeRabbit configuration file

test/**/*: # Test

  • TestCase名は英語で書く。
  • どうしても避けられない時以外にsystem testでsleepは使わない。

Unit Test

model, helper, decorator, view_componentについてはメソッドを追加した場合は必ず対応したUnit TestのTestCaseを1つは書く。

Files:

  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
🧠 Learnings (7)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: reckyy
Repo: fjordllc/bootcamp PR: 8356
File: app/models/notification.rb:45-47
Timestamp: 2025-07-15T12:58:02.735Z
Learning: fjordllc/bootcampプロジェクトの`app/models/notification.rb`において、`training_completed`通知種別は`TARGETS_TO_KINDS`ハッシュに含めない設計になっている。これは`training_completed`が通知一覧のフィルタ対象ではないためで、意図的な設計判断である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • db/fixtures/micro_reports.yml
  • app/models/concerns/mentioner.rb
  • test/models/user_test.rb
  • test/models/micro_report_test.rb
  • app/models/user.rb
  • app/models/micro_report.rb
  • test/system/user/micro_reports_test.rb
  • app/controllers/users/micro_reports_controller.rb
  • test/system/notification/mention_test.rb
📚 Learning: 2025-07-10T12:59:27.807Z
Learnt from: kitarou888
Repo: fjordllc/bootcamp PR: 8277
File: test/models/searcher_test.rb:326-331
Timestamp: 2025-07-10T12:59:27.807Z
Learning: モデルテストにおいて、1つのクラスメソッドの複数の挙動を検証する場合、機能の異なる側面を同じテストメソッドでテストすることは、包括的なテストとして適切である。特に`only_me`のような機能では、異なる検索条件(空文字と具体的な検索語)を使い分けることで、より広範囲な動作保証が可能となる。

Applied to files:

  • test/models/user_test.rb
  • test/system/user/micro_reports_test.rb
📚 Learning: 2025-11-26T08:23:30.927Z
Learnt from: CR
Repo: fjordllc/bootcamp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T08:23:30.927Z
Learning: Applies to test/**/*_test.rb : Use Minitest + Capybara for system tests; place unit and integration tests under matching `test/*` directories

Applied to files:

  • test/models/micro_report_test.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
📚 Learning: 2025-11-26T08:23:30.927Z
Learnt from: CR
Repo: fjordllc/bootcamp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T08:23:30.927Z
Learning: Applies to test/**/*_test.rb : Test suite should use Minitest with structure: `system/`, `models/`, `controllers/`, and fixtures in `test/fixtures/`; test files should be named `*_test.rb`

Applied to files:

  • test/models/micro_report_test.rb
📚 Learning: 2025-09-04T01:27:23.422Z
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: db/fixtures/buzzes.yml:0-0
Timestamp: 2025-09-04T01:27:23.422Z
Learning: The buzz_controller.rb and related data migration files were deleted as part of the Buzz page redesign, not just modified. The old single buzz page was completely replaced with a new buzzes (plural) listing page with year-based navigation and metadata structure.

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
🧬 Code graph analysis (7)
test/models/user_test.rb (2)
test/models/micro_report_test.rb (1)
  • test (5-11)
app/models/user.rb (2)
  • ordered_micro_reports (956-958)
  • page_of_micro_report (960-966)
test/models/micro_report_test.rb (1)
app/models/micro_report.rb (1)
  • path (13-18)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-19)
app/models/micro_report.rb (2)
app/models/user.rb (1)
  • include (3-1029)
test/system/notification/mention_test.rb (1)
  • include (7-94)
test/system/user/micro_reports_test.rb (1)
test/models/micro_report_test.rb (1)
  • test (5-11)
app/controllers/users/micro_reports_controller.rb (1)
app/models/user.rb (2)
  • page_of_micro_report (960-966)
  • ordered_micro_reports (956-958)
test/system/notification/mention_test.rb (1)
test/supports/notification_helper.rb (1)
  • make_mention_notification_message (66-68)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (10)
app/models/concerns/mentioner.rb (1)

27-28: LGTM!

MicroReportのメンション機能が他の既存のケース(Product、Report等)と同じパターンで実装されており、一貫性があります。

test/system/notification/mention_test.rb (1)

80-93: LGTM!

分報のメンション機能のシステムテストが適切に実装されています。既存のメンションテストと同じパターンに従っており、通知の作成から受信者での確認まで正しく検証されています。

db/fixtures/micro_reports.yml (1)

28-33: LGTM!

ページネーションのテストに必要なフィクスチャデータが適切に追加されています。25件のデータ追加によりPAGER_NUMBERの境界値テストが可能になります。

test/models/user_test.rb (2)

761-774: LGTM!

ordered_micro_reportsメソッドのテストが適切に実装されています。created_atの昇順でソートされることを正しく検証しています。


776-790: LGTM!

page_of_micro_reportメソッドのページネーション計算ロジックが正しくテストされています。境界値(1ページ目と2ページ目の境界)も含めて検証されており、十分なカバレッジです。

app/models/user.rb (2)

956-958: LGTM!

ordered_micro_reportsメソッドはシンプルで明確な実装です。分報の昇順ソートを提供しており、可読性が高いです。


960-966: LGTM!

page_of_micro_reportメソッドのページ計算ロジックが正しく実装されています。micro_report_idが見つからない場合のnil返却も適切に処理されています。

test/models/micro_report_test.rb (1)

6-10: LGTM!

MicroReport#pathメソッドのテストが適切に実装されています。期待されるURL形式を正しく検証しています。

test/system/user/micro_reports_test.rb (1)

224-235: LGTM!

micro_report_idパラメータによるリダイレクト機能のシステムテストが適切に実装されています。PAGER_NUMBER定数を使用して実際のページネーション境界をテストしており、リダイレクト後のページ番号と対象要素の存在を正しく検証しています。

app/models/micro_report.rb (1)

5-12: Mentioner の組み込みパターンが既存実装と整合していて良いです

include Mentionermentionable_as :contentalias sender user の組み合わせは、他のメンション対応モデルと同じインターフェースになっていそうで、一貫性もあり問題なさそうです(通知生成側からも扱いやすそうです)。

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru
よかったらレビューしていただけないでしょうか?

期限は2週間前後でお願いしたいですが、特に急いでないのでそれ以降でも構いません。
年末年始で忙しい等であれば他の方にお願いするのでおっしゃってください〜

@tyrrell-IH tyrrell-IH requested a review from yokomaru December 16, 2025 02:02
@yokomaru yokomaru requested review from yokomaru and removed request for yokomaru December 16, 2025 04:32
@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru
#9260
上記のPRと要調整のためレビュー依頼を取り下げさせていただきます。

お騒がせして大変申し訳なかったです🙏

@tyrrell-IH tyrrell-IH removed the request for review from yokomaru December 16, 2025 11:40
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from d31acce to 3b7f580 Compare December 28, 2025 04:03
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/models/user.rb (1)

965-971: ロジックは正しいですが、パフォーマンスについて考慮点があります。

pluck(:id) はすべての ID をメモリにロードするため、分報の件数が非常に多いユーザーの場合にパフォーマンスに影響する可能性があります。ただし、分報はユーザー単位でスコープされているため、通常の利用では問題ないレベルと考えられます。

将来的に件数が増加した場合は、SQL ベースのアプローチ(例: ROW_NUMBER() ウィンドウ関数)への変更を検討してください。

app/controllers/users/micro_reports_controller.rb (1)

11-16: リダイレクトロジックは適切に実装されています。

通知クリック時の遷移処理として、適切なページとアンカーへのリダイレクトが実装されています。@user.micro_reports.find により、他ユーザーの分報へのアクセスも防止されています。

1点だけ軽微な改善提案があります:

params[:micro_report_id] の変換を統一することで、より明確になります。

🔎 軽微な改善提案
 def index
   if params[:micro_report_id].present?
-    micro_report = @user.micro_reports.find(params[:micro_report_id])
-    page = @user.page_of_micro_report(params[:micro_report_id].to_i, PAGER_NUMBER)
+    micro_report_id = params[:micro_report_id].to_i
+    micro_report = @user.micro_reports.find(micro_report_id)
+    page = @user.page_of_micro_report(micro_report_id, PAGER_NUMBER)

     return redirect_to user_micro_reports_path(@user, page:, anchor: "micro_report_#{micro_report.id}")
   end
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d31acce and 3b7f580.

📒 Files selected for processing (9)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • db/fixtures/micro_reports.yml
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/system/notification/mention_test.rb
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/system/user/micro_reports_test.rb
🧰 Additional context used
📓 Path-based instructions (3)
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
db/**

📄 CodeRabbit inference engine (AGENTS.md)

Database migrations and schema should be stored in db/ directory; app-specific utilities in lib/; static assets in public/

Files:

  • db/fixtures/micro_reports.yml
🧠 Learnings (3)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: reckyy
Repo: fjordllc/bootcamp PR: 8356
File: app/models/notification.rb:45-47
Timestamp: 2025-07-15T12:58:02.735Z
Learning: fjordllc/bootcampプロジェクトの`app/models/notification.rb`において、`training_completed`通知種別は`TARGETS_TO_KINDS`ハッシュに含めない設計になっている。これは`training_completed`が通知一覧のフィルタ対象ではないためで、意図的な設計判断である。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • db/fixtures/micro_reports.yml
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
🧬 Code graph analysis (2)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-19)
app/controllers/users/micro_reports_controller.rb (1)
app/models/user.rb (2)
  • page_of_micro_report (965-971)
  • ordered_micro_reports (961-963)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (6)
app/models/concerns/mentioner.rb (1)

27-28: LGTM!

MicroReport 用のブランチが既存のパターンに沿って適切に追加されています。分報にはタイトルがないため、シンプルな形式で正しいです。

db/fixtures/micro_reports.yml (1)

32-37: LGTM!

ページネーションと分報へのリダイレクト機能のテストに必要なフィクスチャが適切に追加されています。comment_user の省略は set_default_comment_user コールバックにより user がデフォルト設定されるため問題ありません。

app/models/user.rb (1)

961-963: LGTM!

シンプルで明確な実装です。コントローラーから参照され、一貫した並び順を提供しています。

app/models/micro_report.rb (2)

15-20: path メソッドの実装は意図通りです。

micro_report_id をクエリパラメータとして渡すことで、コントローラーの index アクションが適切なページとアンカーにリダイレクトできます。分報には専用の show ページがないため、この設計は PR の目的に合致しています。


5-5: Mentionerの統合は適切に実装されています。

mentionable_as :contentalias sender user の組み合わせにより、Mentionerがメンション機能を正しく実装するために必要なすべてのインターフェースが提供されています。mentionable_as マクロはmentionable gem(~> 0.3.0)によって提供され、メンション検出と自動コールバックを設定します。

app/controllers/users/micro_reports_controller.rb (1)

18-18: LGTM!

ordered_micro_reports を使用することで、ページネーション計算と一貫した並び順が保証されています。

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 3b7f580 to 0ad5f17 Compare December 28, 2025 10:45
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/models/user.rb (1)

965-971: 分報数が多い場合のパフォーマンスを考慮できます

現在の実装は pluck(:id) ですべての分報IDをメモリに読み込みます。通常の利用では問題ありませんが、ユーザーが数千件の分報を持つ場合、パフォーマンスに影響する可能性があります。

🔎 SQL COUNT を使用した代替実装案

より効率的なSQL実装の例:

def page_of_micro_report(micro_report_id, per_page)
  target = ordered_micro_reports.find_by(id: micro_report_id)
  return nil unless target

  # Count records before the target micro_report
  count = ordered_micro_reports.where('created_at < ? OR (created_at = ? AND id <= ?)', 
                                      target.created_at, target.created_at, micro_report_id).count
  (count - 1) / per_page + 1
end

ただし、現在の実装でも大多数のユースケースでは十分機能するため、実際のパフォーマンス問題が発生しない限り変更は不要です。

app/controllers/users/micro_reports_controller.rb (1)

11-16: メンション通知からの遷移ロジックが適切に実装されています

@user.micro_reports.find() により、該当する分報がユーザーに属することを確認してから、正しいページとアンカーへリダイレクトしています。セキュリティ面でも問題ありません。

💡 オプション: micro_reportレコード全体の読み込みを避ける方法

現在はLine 12で分報レコード全体を読み込んでいますが、アンカー用にはIDのみ使用しています。存在確認のみが目的であれば、以下のように簡略化できます:

if params[:micro_report_id].present?
  micro_report_id = params[:micro_report_id].to_i
  # 存在確認のみ(レコードを読み込まない)
  unless @user.micro_reports.exists?(micro_report_id)
    raise ActiveRecord::RecordNotFound
  end
  
  page = @user.page_of_micro_report(micro_report_id, PAGER_NUMBER)
  return redirect_to user_micro_reports_path(@user, page:, anchor: "micro_report_#{micro_report_id}")
end

ただし、現在の実装も十分明確で読みやすいため、変更は任意です。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b7f580 and 0ad5f17.

📒 Files selected for processing (9)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • db/fixtures/micro_reports.yml
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (7)
  • test/models/micro_report_test.rb
  • db/fixtures/micro_reports.yml
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
  • app/models/micro_report.rb
  • app/models/concerns/mentioner.rb
  • test/models/user_test.rb
🧰 Additional context used
📓 Path-based instructions (2)
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
🧠 Learnings (3)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: reckyy
Repo: fjordllc/bootcamp PR: 8356
File: app/models/notification.rb:45-47
Timestamp: 2025-07-15T12:58:02.735Z
Learning: fjordllc/bootcampプロジェクトの`app/models/notification.rb`において、`training_completed`通知種別は`TARGETS_TO_KINDS`ハッシュに含めない設計になっている。これは`training_completed`が通知一覧のフィルタ対象ではないためで、意図的な設計判断である。
Learnt from: ryufuta
Repo: fjordllc/bootcamp PR: 9323
File: app/models/question_auto_closer.rb:45-51
Timestamp: 2025-11-25T05:42:10.478Z
Learning: fjordllc/bootcamp の QuestionAutoCloser において、create_warning_message で発行される 'answer.create' イベントは、システムユーザーによる自動クローズ警告メッセージを質問者と既存の監視者に通知するための意図的な設計である。AnswerNotifier と NotifierToWatchingUser による通知は期待される動作。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
🧬 Code graph analysis (2)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-19)
app/controllers/users/micro_reports_controller.rb (1)
app/models/user.rb (2)
  • page_of_micro_report (965-971)
  • ordered_micro_reports (961-963)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (2)
app/models/user.rb (1)

961-963: LGTM!

分報の順序をモデル側でカプセル化する良いリファクタリングです。コントローラーの可読性が向上し、このクエリロジックを他の場所でも再利用できるようになります。

app/controllers/users/micro_reports_controller.rb (1)

18-18: LGTM!

ordered_micro_reports メソッドの使用により、コントローラーがシンプルになり、クエリロジックがモデルにカプセル化されています。

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 0ad5f17 to f0ee5c5 Compare December 30, 2025 10:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/models/user.rb (1)

965-971: 大量データ時のパフォーマンスを考慮してください。

pluck(:id)で全IDをメモリに読み込むため、micro_reportsが数千件を超える場合にパフォーマンスの問題が発生する可能性があります。ただし、分報の性質上、極端に大量のデータになるケースは限定的と考えられるため、現状の実装でも許容範囲内かもしれません。

将来的にスケーラビリティが課題になった場合は、SQL内で位置を計算するアプローチをご検討ください。

🔎 SQLベースの代替実装案
def page_of_micro_report(micro_report_id, per_page)
  result = ordered_micro_reports
    .select('COUNT(*) as position')
    .where('micro_reports.id <= ?', micro_report_id)
    .take
  
  return nil unless result && ordered_micro_reports.exists?(micro_report_id)
  
  (result.position - 1) / per_page + 1
end

ただし、現在の実装のシンプルさとのトレードオフを考慮して判断してください。

app/controllers/users/micro_reports_controller.rb (1)

11-16: ページ計算結果がnilの場合のハンドリングを確認してください。

page_of_micro_reportnilを返す可能性があります(Line 13)。通常はLine 12でActiveRecord::RecordNotFoundが発生するため問題ありませんが、データの不整合がある場合に備えて、明示的なnilチェックを追加することをご検討ください。

🔎 nilチェックを追加する場合の実装例
 if params[:micro_report_id].present?
   micro_report = @user.micro_reports.find(params[:micro_report_id])
   page = @user.page_of_micro_report(params[:micro_report_id].to_i, PAGER_NUMBER)
+  
+  unless page
+    redirect_to user_micro_reports_path(@user), alert: '指定された分報が見つかりませんでした。'
+    return
+  end

   return redirect_to user_micro_reports_path(@user, page:, anchor: "micro_report_#{micro_report.id}")
 end
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ad5f17 and f0ee5c5.

📒 Files selected for processing (10)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/user.rb
  • db/fixtures/micro_reports.yml
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/supports/notification_helper.rb
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (5)
  • test/models/micro_report_test.rb
  • test/system/user/micro_reports_test.rb
  • test/models/user_test.rb
  • app/models/micro_report.rb
  • db/fixtures/micro_reports.yml
🧰 Additional context used
📓 Path-based instructions (5)
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*_test.rb: Test suite should use Minitest with structure: system/, models/, controllers/, and fixtures in test/fixtures/; test files should be named *_test.rb
Use Minitest + Capybara for system tests; place unit and integration tests under matching test/* directories

Files:

  • test/system/notification/mention_test.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • test/system/notification/mention_test.rb
  • app/models/concerns/mentioner.rb
  • app/models/user.rb
  • test/supports/notification_helper.rb
  • app/controllers/users/micro_reports_controller.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • test/system/notification/mention_test.rb
  • app/models/concerns/mentioner.rb
  • app/models/user.rb
  • test/supports/notification_helper.rb
  • app/controllers/users/micro_reports_controller.rb
test/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep tests deterministic and use fixtures stored in test/fixtures/ for test data

Files:

  • test/system/notification/mention_test.rb
  • test/supports/notification_helper.rb
test/**/*

⚙️ CodeRabbit configuration file

test/**/*: # Test

  • TestCase名は英語で書く。
  • どうしても避けられない時以外にsystem testでsleepは使わない。

Unit Test

model, helper, decorator, view_componentについてはメソッドを追加した場合は必ず対応したUnit TestのTestCaseを1つは書く。

Files:

  • test/system/notification/mention_test.rb
  • test/supports/notification_helper.rb
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/concerns/mentioner.rb
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
🧠 Learnings (4)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
📚 Learning: 2025-11-26T08:23:30.927Z
Learnt from: CR
Repo: fjordllc/bootcamp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T08:23:30.927Z
Learning: Applies to test/**/*_test.rb : Use Minitest + Capybara for system tests; place unit and integration tests under matching `test/*` directories

Applied to files:

  • test/system/notification/mention_test.rb
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • test/system/notification/mention_test.rb
  • app/models/concerns/mentioner.rb
  • app/models/user.rb
  • app/controllers/users/micro_reports_controller.rb
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
🧬 Code graph analysis (3)
test/system/notification/mention_test.rb (2)
app/components/users/micro_reports/micro_report_component.rb (1)
  • comment_user (10-12)
test/supports/notification_helper.rb (1)
  • notification_message_for_mention (70-72)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-19)
app/controllers/users/micro_reports_controller.rb (1)
app/models/user.rb (2)
  • page_of_micro_report (965-971)
  • ordered_micro_reports (961-963)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (5)
app/models/concerns/mentioner.rb (1)

27-28: LGTM!

MicroReportに対するメンション処理が既存のパターンに沿って正しく実装されています。

app/models/user.rb (1)

961-963: LGTM!

シンプルで明確な実装です。コントローラーで使用される順序付きmicro_reportsを提供しています。

app/controllers/users/micro_reports_controller.rb (1)

18-18: LGTM!

ordered_micro_reportsメソッドの使用により、コードがより読みやすく保守しやすくなっています。

test/system/notification/mention_test.rb (1)

80-95: LGTM!

分報からのメンション機能のシステムテストが適切に実装されています。既存のテストパターンに沿っており、主要な動作フローをカバーしています。

test/supports/notification_helper.rb (1)

70-72: LGTM!

分報のメンション通知メッセージをフォーマットするヘルパーメソッドが適切に実装されています。既存のヘルパーパターンに従っており、テストコードで再利用可能です。

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from f0ee5c5 to 5bd4b9c Compare January 3, 2026 00:50
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/models/user.rb (1)

965-971: パフォーマンスの最適化を検討できます(オプション)。

ロジックは正しく動作しますが、pluck(:id)で全てのIDをメモリに読み込むため、分報の数が非常に多い場合(例:数千件以上)にパフォーマンスへの影響が考えられます。

ただし、通常の使用パターンではこの実装で問題ないと思われます。将来的にパフォーマンス問題が発生した場合は、SQLベースのページ計算(COUNT と OFFSET を使用)への変更を検討できます。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0ee5c5 and 5bd4b9c.

📒 Files selected for processing (7)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/micro_report.rb
  • app/models/micro_report_callbacks.rb
  • app/models/user.rb
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (5)
  • test/models/user_test.rb
  • test/system/user/micro_reports_test.rb
  • app/models/micro_report.rb
  • app/controllers/users/micro_reports_controller.rb
  • test/models/micro_report_test.rb
🧰 Additional context used
📓 Path-based instructions (2)
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/user.rb
  • app/models/micro_report_callbacks.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/models/user.rb
  • app/models/micro_report_callbacks.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/user.rb
  • app/models/micro_report_callbacks.rb
🧠 Learnings (2)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
Learnt from: matuaya
Repo: fjordllc/bootcamp PR: 9108
File: app/models/after_user_retirement.rb:0-0
Timestamp: 2025-09-01T22:31:57.345Z
Learning: fjordllc/bootcampプロジェクトにおいて、`Newspaper.publish(:retirement_create, { user: user })`はUnfinishedDataDestroyer(未チェックProduct・WIP Report削除、career_pathリセット)とTimesChannelDestroyer(Discord分報チャンネル削除)による重要なデータクリーンアップ処理を実行するため、退会のトリガーが何であろうと(admin、hibernation、user)必ず実行する必要がある。
Learnt from: matuaya
Repo: fjordllc/bootcamp PR: 9108
File: app/models/after_user_retirement.rb:0-0
Timestamp: 2025-09-01T22:31:57.345Z
Learning: fjordllc/bootcampプロジェクトにおいて、`Newspaper.publish(:retirement_create, { user: user })`は通知処理ではなく、UnfinishedDataDestroyerやTimesChannelDestroyer等による重要なデータクリーンアップ処理を実行するため、管理者による退会(triggered_by: 'admin')の場合でも必ず実行する必要がある。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • app/models/user.rb
  • app/models/micro_report_callbacks.rb
🧬 Code graph analysis (2)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-25)
app/models/micro_report_callbacks.rb (1)
app/models/micro_report.rb (1)
  • path (17-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (2)
app/models/user.rb (1)

961-963: 実装が適切です。

分報を作成日時の昇順で取得するメソッドで、コントローラーでのページネーション処理と一貫性があります。命名も明確で分かりやすいです。

app/models/micro_report_callbacks.rb (1)

1-13: 実装が適切です。

分報削除時に関連する通知を削除するコールバッククラスで、実装は明確です。destroy_allを使用することでコールバックが実行され、micro_report.pathをキーに通知を検索する仕組みも適切です。

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 5bd4b9c to a43e565 Compare January 3, 2026 01:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/models/user.rb (1)

965-971: per_pageパラメータの妥当性検証を検討してください

per_pageが0または負の値の場合、ゼロ除算または予期しない動作が発生する可能性があります。コントローラー側で定数PAGER_NUMBERを使用しているため現在は問題になりませんが、このメソッドがパブリックAPIとして他の場所から呼び出される可能性を考慮すると、防御的なバリデーションを追加することを推奨します。

🔎 提案される修正
 def page_of_micro_report(micro_report_id, per_page)
+  return nil if per_page <= 0
+
   ids = ordered_micro_reports.pluck(:id)
   index = ids.index(micro_report_id)
   return nil unless index

   index / per_page + 1
 end
app/models/micro_report_callbacks.rb (1)

10-11: destroy_alldelete_all のパフォーマンスを検討してください

destroy_all は各通知のコールバックを実行しますが、Notification モデルに削除時の重要なコールバックがない場合、delete_all を使用することでパフォーマンスが向上します。メンション通知の数が限定的であれば現在の実装でも問題ありませんが、将来的な最適化の余地として検討する価値があります。

🔎 delete_all を使用する場合の実装例
  def delete_notification(micro_report)
-    Notification.where(link: micro_report.path).destroy_all
+    Notification.where(link: micro_report.path).delete_all
  end

注意: Notification モデルに削除時の重要なコールバック(dependent: :destroy な関連など)がある場合は、現在の destroy_all を維持してください。

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bd4b9c and a43e565.

📒 Files selected for processing (11)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/micro_report_callbacks.rb
  • app/models/user.rb
  • db/fixtures/micro_reports.yml
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/supports/notification_helper.rb
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (5)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
🧰 Additional context used
📓 Path-based instructions (6)
db/**

📄 CodeRabbit inference engine (AGENTS.md)

Database migrations and schema should be stored in db/ directory; app-specific utilities in lib/; static assets in public/

Files:

  • db/fixtures/micro_reports.yml
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/models/micro_report_callbacks.rb
  • app/models/user.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/models/micro_report_callbacks.rb
  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
  • app/models/user.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/models/micro_report_callbacks.rb
  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
  • app/models/user.rb
test/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep tests deterministic and use fixtures stored in test/fixtures/ for test data

Files:

  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
test/**/*

⚙️ CodeRabbit configuration file

test/**/*: # Test

  • TestCase名は英語で書く。
  • どうしても避けられない時以外にsystem testでsleepは使わない。

Unit Test

model, helper, decorator, view_componentについてはメソッドを追加した場合は必ず対応したUnit TestのTestCaseを1つは書く。

Files:

  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*_test.rb: Test suite should use Minitest with structure: system/, models/, controllers/, and fixtures in test/fixtures/; test files should be named *_test.rb
Use Minitest + Capybara for system tests; place unit and integration tests under matching test/* directories

Files:

  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
🧠 Learnings (5)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: reckyy
Repo: fjordllc/bootcamp PR: 8356
File: app/models/notification.rb:45-47
Timestamp: 2025-07-15T12:58:02.735Z
Learning: fjordllc/bootcampプロジェクトの`app/models/notification.rb`において、`training_completed`通知種別は`TARGETS_TO_KINDS`ハッシュに含めない設計になっている。これは`training_completed`が通知一覧のフィルタ対象ではないためで、意図的な設計判断である。
Learnt from: ryufuta
Repo: fjordllc/bootcamp PR: 9323
File: app/models/question_auto_closer.rb:45-51
Timestamp: 2025-11-25T05:42:10.478Z
Learning: fjordllc/bootcamp の QuestionAutoCloser において、create_warning_message で発行される 'answer.create' イベントは、システムユーザーによる自動クローズ警告メッセージを質問者と既存の監視者に通知するための意図的な設計である。AnswerNotifier と NotifierToWatchingUser による通知は期待される動作。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
Learnt from: matuaya
Repo: fjordllc/bootcamp PR: 9108
File: app/models/after_user_retirement.rb:0-0
Timestamp: 2025-09-01T22:31:57.345Z
Learning: fjordllc/bootcampプロジェクトにおいて、`Newspaper.publish(:retirement_create, { user: user })`はUnfinishedDataDestroyer(未チェックProduct・WIP Report削除、career_pathリセット)とTimesChannelDestroyer(Discord分報チャンネル削除)による重要なデータクリーンアップ処理を実行するため、退会のトリガーが何であろうと(admin、hibernation、user)必ず実行する必要がある。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • db/fixtures/micro_reports.yml
  • app/models/micro_report_callbacks.rb
  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
  • app/models/user.rb
📚 Learning: 2025-11-26T08:23:30.927Z
Learnt from: CR
Repo: fjordllc/bootcamp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T08:23:30.927Z
Learning: Applies to test/**/*_test.rb : Use Minitest + Capybara for system tests; place unit and integration tests under matching `test/*` directories

Applied to files:

  • test/system/user/micro_reports_test.rb
  • test/system/notification/mention_test.rb
📚 Learning: 2025-07-10T12:59:27.807Z
Learnt from: kitarou888
Repo: fjordllc/bootcamp PR: 8277
File: test/models/searcher_test.rb:326-331
Timestamp: 2025-07-10T12:59:27.807Z
Learning: モデルテストにおいて、1つのクラスメソッドの複数の挙動を検証する場合、機能の異なる側面を同じテストメソッドでテストすることは、包括的なテストとして適切である。特に`only_me`のような機能では、異なる検索条件(空文字と具体的な検索語)を使い分けることで、より広範囲な動作保証が可能となる。

Applied to files:

  • test/system/user/micro_reports_test.rb
📚 Learning: 2025-07-30T07:26:36.599Z
Learnt from: ryufuta
Repo: fjordllc/bootcamp PR: 8992
File: app/models/correct_answer_notifier.rb:23-23
Timestamp: 2025-07-30T07:26:36.599Z
Learning: Railsの標準的なヘルパーメソッド(例:`question_url`、`user_path`など)が通常の方法で使用されている場合、それらの動作テストは不要である。これらのメソッドはRailsフレームワーク自体でテストされており、アプリケーション固有のロジックではないため。

Applied to files:

  • test/system/user/micro_reports_test.rb
🧬 Code graph analysis (3)
app/models/micro_report_callbacks.rb (1)
app/models/micro_report.rb (1)
  • path (18-23)
test/system/notification/mention_test.rb (2)
app/components/users/micro_reports/micro_report_component.rb (1)
  • comment_user (10-12)
test/supports/notification_helper.rb (1)
  • notification_message_for_mention (70-72)
app/models/user.rb (1)
app/controllers/users/micro_reports_controller.rb (1)
  • index (10-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (8)
db/fixtures/micro_reports.yml (1)

32-37: LGTM!

ページネーションのテストに必要な十分なフィクスチャデータが追加されています。

app/models/user.rb (2)

961-963: LGTM!

分報を作成日時の昇順で取得するシンプルで明確な実装です。


961-971: ユニットテストは既に実装済みです

test/models/user_test.rbにおいて、両メソッドのテストが既に追加されています:

  • #ordered_micro_reports(776-787行):created_at による昇順ソートを検証
  • #page_of_micro_report(789-803行):複数レポートのページネーション計算を検証
test/system/notification/mention_test.rb (1)

80-95: LGTM!

分報のメンション機能のシステムテストが適切に実装されています。既存のメンションテストのパターンに従い、投稿から通知確認までのエンドツーエンドのフローをカバーしています。

test/supports/notification_helper.rb (1)

70-72: LGTM!

分報のメンション通知メッセージをフォーマットするヘルパーメソッドが適切に実装されています。既存のヘルパーメソッドのパターンに従い、テストコードの可読性を向上させています。

test/system/user/micro_reports_test.rb (2)

236-247: LGTM!

micro_report_idパラメータを使用した特定の分報へのリダイレクト機能が適切にテストされています。ページ番号の計算とアンカーへの遷移を正しく検証しています。


249-256: LGTM!

存在しないmicro_report_idに対するエラーハンドリングが適切にテストされています。アラートメッセージの表示とフォールバック動作を正しく検証しています。

app/models/micro_report_callbacks.rb (1)

3-6: コールバックパターンの実装が適切です

PORを使用したコールバックオブジェクトパターンにより、MicroReportモデルをスリムに保ちつつ、削除時の処理を明確に分離できています。コーディングガイドラインに沿った設計です。

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from a43e565 to 42b9be9 Compare January 3, 2026 03:56
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/controllers/users/micro_reports_controller.rb (1)

20-21: 既存の変数を使用して冗長性を削減

Line 20でparams[:micro_report_id].to_iを使用していますが、Line 12で既にmicro_report変数を取得しています。一貫性と可読性のため、micro_report.idを使用することを推奨します。

🔎 提案される修正
-      page = @user.page_of_micro_report(params[:micro_report_id].to_i, PAGER_NUMBER)
+      page = @user.page_of_micro_report(micro_report.id, PAGER_NUMBER)
       return redirect_to user_micro_reports_path(@user, page:, anchor: "micro_report_#{micro_report.id}")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a43e565 and 42b9be9.

📒 Files selected for processing (12)
  • app/controllers/users/micro_reports_controller.rb
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • app/models/micro_report_callbacks.rb
  • app/models/user.rb
  • app/views/activity_mailer/mentioned.html.slim
  • db/fixtures/micro_reports.yml
  • test/models/micro_report_test.rb
  • test/models/user_test.rb
  • test/supports/notification_helper.rb
  • test/system/notification/mention_test.rb
  • test/system/user/micro_reports_test.rb
🚧 Files skipped from review as they are similar to previous changes (7)
  • app/models/concerns/mentioner.rb
  • app/models/micro_report.rb
  • test/models/micro_report_test.rb
  • app/models/user.rb
  • db/fixtures/micro_reports.yml
  • test/system/notification/mention_test.rb
  • test/models/user_test.rb
🧰 Additional context used
📓 Path-based instructions (6)
app/**/*.{rb,js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Rails app code should be organized in app/ directory with subdirectories: models/, controllers/, views/, jobs/, helpers/, and frontend code under javascript/ (Shakapacker)

Files:

  • app/controllers/users/micro_reports_controller.rb
  • app/models/micro_report_callbacks.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Ruby code should use 2-space indentation, snake_case for method names, and CamelCase for class names, enforced by RuboCop (.rubocop.yml)

Files:

  • app/controllers/users/micro_reports_controller.rb
  • app/models/micro_report_callbacks.rb
  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb

⚙️ CodeRabbit configuration file

**/*.rb: # refactoring

  • まずFat Controllerを避け、次にFat Modelを避ける。
  • Serviceクラスの乱用を避ける。
  • controller concernを作ろうとしたらPORO(Plain Old Ruby Object)やActiveRecordモデルでの実装で代替できないか検討する。

Rails Patterns

  • ViewHelperにメソッドを実装する時にはまずDecoratorパターンを使うことを検討する。(active_decorator gemを導入しているのでそれを使う)
  • 複雑なActiveRecordクエリがあり、再利用できそうな場合はQueryObjectパターンを検討する。(rails-patterns gemを導入しているのでそれのQuery機能を使う)
  • Viewにpartialを作る場合はViewComponentを使うことを検討する。
  • 複数のActiveRecordモデルを操作する1つの責務がある時や外部APIとやりとりする処理がある場合にはInteractorオブジェクトパターンを検討する。(interactor gemを導入しているのでそれを使う)
  • 複数のInteractorを実行するような処理がある場合Organizerオブジェクトパターンを検討する。(interactor gemを導入しており、その中にOrganizerの機能があるので使う)

Files:

  • app/controllers/users/micro_reports_controller.rb
  • app/models/micro_report_callbacks.rb
  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
**/*.slim

📄 CodeRabbit inference engine (AGENTS.md)

Slim templates should be linted according to config/slim_lint.yml

Files:

  • app/views/activity_mailer/mentioned.html.slim
test/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep tests deterministic and use fixtures stored in test/fixtures/ for test data

Files:

  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
test/**/*

⚙️ CodeRabbit configuration file

test/**/*: # Test

  • TestCase名は英語で書く。
  • どうしても避けられない時以外にsystem testでsleepは使わない。

Unit Test

model, helper, decorator, view_componentについてはメソッドを追加した場合は必ず対応したUnit TestのTestCaseを1つは書く。

Files:

  • test/supports/notification_helper.rb
  • test/system/user/micro_reports_test.rb
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*_test.rb: Test suite should use Minitest with structure: system/, models/, controllers/, and fixtures in test/fixtures/; test files should be named *_test.rb
Use Minitest + Capybara for system tests; place unit and integration tests under matching test/* directories

Files:

  • test/system/user/micro_reports_test.rb
🧠 Learnings (7)
📓 Common learnings
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/models/graduation_notifier.rb:23-28
Timestamp: 2025-09-12T21:16:47.639Z
Learning: Rails upgrade PRにおいて、configuration systemの変更やwebhook設定の改善提案も、アップグレードに直接関連しない場合は別PRで対応すべきである。PRのスコープ維持が重要。
Learnt from: reckyy
Repo: fjordllc/bootcamp PR: 8356
File: app/models/notification.rb:45-47
Timestamp: 2025-07-15T12:58:02.735Z
Learning: fjordllc/bootcampプロジェクトの`app/models/notification.rb`において、`training_completed`通知種別は`TARGETS_TO_KINDS`ハッシュに含めない設計になっている。これは`training_completed`が通知一覧のフィルタ対象ではないためで、意図的な設計判断である。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: ryufuta
Repo: fjordllc/bootcamp PR: 9323
File: app/models/question_auto_closer.rb:45-51
Timestamp: 2025-11-25T05:42:10.478Z
Learning: fjordllc/bootcamp の QuestionAutoCloser において、create_warning_message で発行される 'answer.create' イベントは、システムユーザーによる自動クローズ警告メッセージを質問者と既存の監視者に通知するための意図的な設計である。AnswerNotifier と NotifierToWatchingUser による通知は期待される動作。
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。
📚 Learning: 2025-11-19T07:55:51.504Z
Learnt from: smallmonkeykey
Repo: fjordllc/bootcamp PR: 9314
File: app/helpers/page_tabs/dashboard_helper.rb:8-12
Timestamp: 2025-11-19T07:55:51.504Z
Learning: fjordllc/bootcamp プロジェクトにおいて、分報(micro_reports)は current_user 専用の機能ではなく、他ユーザーの分報も閲覧・管理する UI で使われているため、ダッシュボードの「自分の分報」タブでは user_micro_reports_path(current_user, ...) を使用し、/users/:id/micro_reports の URL 構造を維持する。current_user 名前空間に新しいルートを追加しない方針である。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
  • app/models/micro_report_callbacks.rb
  • test/system/user/micro_reports_test.rb
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 8977
File: app/controllers/reports_controller.rb:63-63
Timestamp: 2025-07-23T20:31:13.856Z
Learning: fjordllc/bootcampプロジェクトの`app/controllers/reports_controller.rb`において、`create`と`update`アクションは両方とも`report.save_uniquely`を使用し、同じ`:report_save`イベントと`'report.save'`イベントを発行する。これは両方とも本質的に「レポートの保存」操作であり、作成と更新を区別する必要がないためである。

Applied to files:

  • app/controllers/users/micro_reports_controller.rb
📚 Learning: 2025-07-23T21:11:21.826Z
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 0
File: :0-0
Timestamp: 2025-07-23T21:11:21.826Z
Learning: fjordllc/bootcampプロジェクトの`app/models/inquiry_notifier.rb`において、`NOTIFICATION_SENDER_NAME`で指定される管理者ユーザーは必ず存在することがシステムの前提条件として保証されているため、senderがnilになることは想定されておらず、エラーハンドリングは不要である。

Applied to files:

  • app/views/activity_mailer/mentioned.html.slim
📚 Learning: 2025-11-26T08:23:30.927Z
Learnt from: CR
Repo: fjordllc/bootcamp PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T08:23:30.927Z
Learning: Applies to test/**/*_test.rb : Use Minitest + Capybara for system tests; place unit and integration tests under matching `test/*` directories

Applied to files:

  • test/system/user/micro_reports_test.rb
📚 Learning: 2025-07-10T12:59:27.807Z
Learnt from: kitarou888
Repo: fjordllc/bootcamp PR: 8277
File: test/models/searcher_test.rb:326-331
Timestamp: 2025-07-10T12:59:27.807Z
Learning: モデルテストにおいて、1つのクラスメソッドの複数の挙動を検証する場合、機能の異なる側面を同じテストメソッドでテストすることは、包括的なテストとして適切である。特に`only_me`のような機能では、異なる検索条件(空文字と具体的な検索語)を使い分けることで、より広範囲な動作保証が可能となる。

Applied to files:

  • test/system/user/micro_reports_test.rb
📚 Learning: 2025-07-30T07:26:36.599Z
Learnt from: ryufuta
Repo: fjordllc/bootcamp PR: 8992
File: app/models/correct_answer_notifier.rb:23-23
Timestamp: 2025-07-30T07:26:36.599Z
Learning: Railsの標準的なヘルパーメソッド(例:`question_url`、`user_path`など)が通常の方法で使用されている場合、それらの動作テストは不要である。これらのメソッドはRailsフレームワーク自体でテストされており、アプリケーション固有のロジックではないため。

Applied to files:

  • test/system/user/micro_reports_test.rb
🧬 Code graph analysis (2)
app/controllers/users/micro_reports_controller.rb (1)
app/models/user.rb (2)
  • page_of_micro_report (965-971)
  • ordered_micro_reports (961-963)
app/models/micro_report_callbacks.rb (1)
app/models/micro_report.rb (1)
  • path (18-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (6)
app/controllers/users/micro_reports_controller.rb (1)

24-24: LGTM!

ordered_micro_reportsメソッドを使用することで、ソート処理をモデルに委譲し、コントローラーの責務を適切に分離できています。

test/supports/notification_helper.rb (1)

70-72: LGTM!

分報のメンション通知メッセージを生成するヘルパーメソッドの実装が適切です。既存のヘルパーメソッドのパターンに従っており、privateセクションに正しく配置されています。

test/system/user/micro_reports_test.rb (2)

236-247: LGTM!

micro_report_idパラメータを指定した場合の対象分報ページへのリダイレクト動作を適切にテストしています。ページ番号とアンカーの両方を検証しており、実装が正しいことを確認できます。


249-256: LGTM!

存在しないmicro_report_idを指定した場合のエラーハンドリングを適切にテストしています。アラートメッセージの検証も含まれており、ユーザーへのフィードバックが正しく機能することを確認できます。

app/models/micro_report_callbacks.rb (1)

1-13: LGTM!

MicroReportの削除時に関連する通知を自動的にクリーンアップするコールバック実装が適切です。micro_report.pathを使用して関連通知を特定する設計は、他のモデルのパターンと一貫性があります。

app/views/activity_mailer/mentioned.html.slim (1)

2-2: この変更は安全です - すべてのmentionableタイプが既にsenderメソッドを定義しています

Report、Comment、Question、Answer、Product、Page、Announcement、CheckおよびArticleを含むすべてのMentionerを含むモデルに対して、既にsenderエイリアスが定義されています。MicroReportはcomment_userを、その他のモデルはusersenderとして定義しており、@mentionable.user.login_nameから@mentionable.sender.login_nameへの変更は既存の実装と一貫性を持ち、NoMethodErrorは発生しません。

Likely an incorrect or invalid review comment.

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 42b9be9 to 345e5fd Compare January 3, 2026 06:28
@yokomaru
Copy link
Copy Markdown
Contributor

yokomaru commented Jan 8, 2026

@tyrrell-IH
お疲れ様です!すみません、なぜかメンションが飛んできておらず今気づきました!💦
ご連絡遅くなり失礼いたしました!🙏
こちら指定いただいた期間内でレビューできるよう対応いたします!

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru
実は私からのメンションが飛んでいなかったという方が今までも何人かいらっしゃって、もしかしたらこちら側の原因かもしれません。。

3週間〜とかでも全然大丈夫ですのでよろしくお願いします〜

@yokomaru
Copy link
Copy Markdown
Contributor

@tyrrell-IH
お疲れ様です!こちら本日〜明日中にご返信いたします!
ご連絡ギリギリで申し訳ありません🙇
よろしくお願いいたします。

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru

ご連絡ありがとうございます🙏
特に急いでなくて時間かかっても大丈夫ですのでよろしくお願いします〜

Copy link
Copy Markdown
Contributor

@yokomaru yokomaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyrrell-IH
お疲れ様です!レビューを返すのが遅くなってしまい大変申し訳ありません!🙏

動作確認は問題なく、実装やテストも丁寧に書かれていて勉強になりました!
手順の動線も分かりやすくとても検証しやすかったです👍👍

1点だけ意図をお伺いしたい箇所があり、そちらにコメントしていますのでご確認いただけますと幸いです🙌

Comment thread app/models/user.rb Outdated
Comment on lines +961 to +973
def ordered_micro_reports
micro_reports.order(created_at: :asc)
end

def page_of_micro_report(micro_report_id, per_page)
return nil if per_page <= 0

ids = ordered_micro_reports.pluck(:id)
index = ids.index(micro_report_id)
return nil unless index

index / per_page + 1
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ordered_micro_reportspage_of_micro_reportUserモデル側に置いている意図について確認させてください!💡

並び順や自身のページを返すような「分報自身(分報のまとまり)を扱うロジック」はUserが持つよりも、MicroReport側にある方がモデルとして責務が分離できるのかな?と思いました!

以下のような感じをイメージしております。

  • 並び順はMicroReport側にscopeとして切り出す
  • ページはMicroReportに分報のまとまりと対象IDとper_pageを渡して何ページ目かを返してもらう

ただuser/:id/micro_reportsというリソースを操作している観点では、現状の置き場所でも不自然でないとも感じていて判断が難しい部分だなと思っており、今回Userモデル側に定義いただいた意図や背景があればぜひお伺いできたらと思いました!🙌

処理自体はindexメソッドからインデックスを取得するところなど、とてもすっきり書けていて勉強になりました!✨

Copy link
Copy Markdown
Contributor Author

@tyrrell-IH tyrrell-IH Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回Userモデル側に定義いただいた意図や背景があればぜひお伺いできたらと思いました!🙌

micro_reports_controller.rb内で@user.micro_reportsのようにユーザーの関連で分報を引く書き方が多かったので、Userクラスのインスタンスを起点に分報の並びを考える方がいいのかなと思って@user.並び替えられた分報を返すメソッドの形でずっと考えてました。

責務をUserに置くかMicroReportに置くかの観点をあまり深く考えていませんでした😓

並び順や自身のページを返すような「分報自身(分報のまとまり)を扱うロジック」はUserが持つよりも、MicroReport側にある方がモデルとして責務が分離できるのかな?と思いました!

この指摘はその通りだと思ったので、MicroReportモデルクラスのクラスメソッドpage_number_forに作り直しました。

基本的な構成は

並び順はMicroReport側にscopeとして切り出す
ページはMicroReportに分報のまとまりと対象IDとper_pageを渡して何ページ目かを返してもらう

を参考にさせていただきました。

なお、以下2点page_number_for内のちょっとした変更があります

  • per_page <= 0の箇所で数値以外と比較してエラーが出ないようにper_page = per_page.to_iの行を追加
  • キーワード引数の方がメソッドの内容を理解しやすいと思ってキーワード引数にしました。が、過剰であれば普通の引数に戻します。 https://bootcamp.fjord.jp/articles/134

b8e0120

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正ありがとうございます!
メソッド名もMicroReport を起点とした名称として、何を返してくれるか役割がわかりやすくて流石です・・・!!

以下の対応も堅牢かつわかりやすいコードになっていてとても参考になりました🙌

per_page <= 0の箇所で数値以外と比較してエラーが出ないようにper_page = per_page.to_iの行を追加
キーワード引数の方がメソッドの内容を理解しやすいと思ってキーワード引数にしました

レビューしておきながらこれらの処理はどのモデルに置くのが良いか悩んでいたのですが、
tyrrellさんが丁寧に検討してくださったおかげですごく腑に落ちました!
ご意見を聞けて本当に良かったです!ありがとうございましたー!

@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 81e3a86 to ba25cf1 Compare January 31, 2026 02:09
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from ba25cf1 to 0da860b Compare January 31, 2026 11:33
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 0da860b to 834b2a7 Compare February 2, 2026 01:10
@tyrrell-IH tyrrell-IH force-pushed the feature/send-notification-when-mentioned-in-micro-report branch from 834b2a7 to b8e0120 Compare February 2, 2026 02:29
@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru

遅くなりましたがレビューを受けての修正を行いました!

お時間のある時にご確認ください🙏

@tyrrell-IH tyrrell-IH requested a review from yokomaru February 2, 2026 06:35
Copy link
Copy Markdown
Contributor

@yokomaru yokomaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

お疲れ様です!修正いただきありがとうございます!

1点コメントしたのですが、ほんの少しコードが短くなるかな?くらいなので修正いただかなくても大丈夫です👍
Approveさせていただきます!

引き続きどうぞよろしくお願いしますー!

Comment thread app/models/micro_report.rb Outdated
per_page = per_page.to_i
return nil if per_page <= 0

ids = scope.ordered.pluck(:id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NITS]
主キーをpluckする場合はidsを使うとよりスッキリ書けそうな気がします💡
(コードを見ると結局pluck(:id)のエイリアスのようなので、どっちでも良さそうなので修正はお任せします!)
https://github.com/rails/rails/blob/984c3ef2775781d47efa9f541ce570daa2434a80/activerecord/lib/active_record/relation/calculations.rb#L242

Copy link
Copy Markdown
Contributor Author

@tyrrell-IH tyrrell-IH Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idsの方がRailsっぽいので、ids採用させていただきました!

ご指摘いただきありがとうございます🙏

commit: da79e72

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@yokomaru
レビューありがとうございました!
#9308 (comment)
のNITSも採用させていただき、修正しました!

自分では気づかない観点からのレビューを頂けてすごく勉強になりました🙌

@komagata
チームメンバーのレビューが終わったので、レビューお願いします〜

Copy link
Copy Markdown
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認させていただきました。OKです〜🙆‍♂️

@komagata komagata merged commit db637c0 into main Feb 9, 2026
7 checks passed
@komagata komagata deleted the feature/send-notification-when-mentioned-in-micro-report branch February 9, 2026 01:09
@github-actions github-actions Bot mentioned this pull request Feb 9, 2026
11 tasks
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.

3 participants