Skip to content

研修生が提出物合格になった際、その研修生が所属する企業のアドバイザーにも通知の実装#9680

Merged
komagata merged 6 commits intomainfrom
feature/add-advisor-notification-on-pass
Mar 25, 2026
Merged

研修生が提出物合格になった際、その研修生が所属する企業のアドバイザーにも通知の実装#9680
komagata merged 6 commits intomainfrom
feature/add-advisor-notification-on-pass

Conversation

@y-kawahara-gs
Copy link
Copy Markdown
Contributor

@y-kawahara-gs y-kawahara-gs commented Feb 25, 2026

Issue

概要

研修生の提出物が合格した際にアドバイザーにも合格通知の送る機能を実装

変更確認方法

  1. feature/add-advisor-notification-on-passをローカルに取り込む
  2. ローカルサーバを起動する
  3. komagataでログインする
  4. http://localhost:3000/products/613458348 に遷移する
  5. 合格にするという赤いボタンをクリックする(すでに合格状態の場合は取り消してから行う)
  6. ログアウトし、kensyuでログインする
  7. 研修生への合格通知の文言が{{メンター}}さんが提出物「OS X Mountain Lionをクリーンインストールする」を合格にしました。になっているかを確認する
  8. ログアウトし、senpaiでログインする
  9. アドバイザーへの合格通知の文言が{{メンター}}さんが{{研修生の名前}}の提出物「OS X Mountain Lionをクリーンインストールする」を合格にしました。になっているかを確認する
  10. http://localhost:3000/letter_opener に遷移し、senpai宛てにメール通知が届いていること、senpai宛てのメールにはkensyuさんの名前が文言に入っていることを確認する(Subjectは例外)

Screenshot

  • 研修生への合格通知(変更なし)
image
  • アドバイザーへの通知
image
  • 研修生宛てのメール通知(変更なし)
image
  • アドバイザー宛てのメール通知
image

Summary by CodeRabbit

  • 新機能
    • チェック作成時、トレーニーの所属先の指導者(アドバイザー)へ通知が届く条件が追加され、指導者向けにはトレーニー名を含む表記で通知されます。
  • 改善
    • 通知の件名がチェック対象の所有者の表示名を使用するよう修正され、受信者の役割に応じて本文の表記が切り替わります。
  • テスト
    • 文面の差分を検証するシステム/単体テストとテストデータを追加しました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 25, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

チェック承認時の件名/本文生成が受信者の役割(研修生 vs アドバイザー)に応じて変わり、チェック作成時に研修生の所属企業のアドバイザーへ追加通知を送るロジックが追加されました。メーラー、ノティファイア、ビュー、コールバック、テスト、フィクスチャが更新されています。

Changes

Cohort / File(s) Summary
メーラー更新
app/mailers/activity_mailer.rb, app/mailers/notification_mailer.rb
checked通知の件名でチェック対象所有者のlogin_nameを使用するよう変更(受信者名ではなく対象所有者名を表示)。
ノティファイア・ビュー更新
app/notifiers/activity_notifier.rb, app/views/activity_mailer/checked.html.slim
受信者がアドバイザー文脈かで前置詞句(kensyu_user)を付与するようにし、通知タイトル/本文を動的に生成するよう変更。
チェックコールバック拡張
app/models/check_callbacks.rb
after_createで、チェック対象が研修生かつ別ユーザーの場合にその企業のアドバイザー群へ通知を送るnotify_adviserssend_notificationを追加。既存の通知フローは保持。
テスト・フィクスチャ追加
test/fixtures/products.yml, test/fixtures/checks.yml
product75と対応するチェックフィクスチャを追加。
テスト追加
test/mailers/activity_mailer_test.rb, test/system/notification/products_test.rb
研修生とアドバイザーで承認通知の文言が異なることを検証する単体・システムテストを追加(受信者ごとの件名/本文の期待値を追加)。

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    participant User as チェック実行者
    end
    rect rgba(200,255,200,0.5)
    participant CheckCallbacks as CheckCallbacks
    participant Company as Company/Advisers
    end
    rect rgba(255,200,200,0.5)
    participant ActivityDelivery as ActivityDelivery
    participant ActivityNotifier as ActivityNotifier
    participant Mailer as ActivityMailer/NotificationMailer
    end

    User->>CheckCallbacks: create Check
    CheckCallbacks-->>Company: 条件判定(別ユーザーか/研修生か)
    alt 研修生かつ企業のアドバイザー有り
      Company->>CheckCallbacks: advisers一覧
      CheckCallbacks->>ActivityDelivery: ActivityDelivery.with(check:, receiver:).notify(:checked) を複数送信
    else 通常受信者のみ
      CheckCallbacks->>ActivityDelivery: 既存の通知送信
    end
    ActivityDelivery->>ActivityNotifier: deliver checked
    ActivityNotifier->>Mailer: 件名・本文を生成(kensyu_userで調整)
    Mailer->>Company: メール/通知を配信
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • okuramasafumi
  • matuaya
  • komagata

Poem

🐰 ちいさな足で知らせに行くよ
名前をそっと前にのせて伝えるよ
研修生にも先輩にも届くように
ひとことがつながって広がって
ぴょんと笑顔の輪が増えるよ

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、研修生が提出物合格になった際にアドバイザーにも通知する実装という変更内容を明確に説明しており、主要な変更と完全に関連している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed プルリクエストの説明は基本的な構成を備えており、Issue番号、概要、変更確認方法、スクリーンショットが含まれています。

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/add-advisor-notification-on-pass
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch from 3635601 to e1dc86e Compare February 25, 2026 01:35
@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch 5 times, most recently from da0a5d9 to 7747e29 Compare March 11, 2026 23:28
@y-kawahara-gs y-kawahara-gs marked this pull request as ready for review March 11, 2026 23:47
@github-actions github-actions bot requested a review from komagata March 11, 2026 23:47
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/mailers/activity_mailer.rb (1)

159-169: ⚠️ Potential issue | 🟠 Major

checked メールのリンク先が提出物ではありません

Line 164-166 の @link_url は受信者プロフィール (/users/:id) を向いたままです。app/views/activity_mailer/checked.html.slim の「この提出物へ」リンクもこれを使うので、今回追加したアドバイザー向けメールから提出物へ遷移できません。check.checkable のパスを使う形に揃えた方がよいです。

💡 修正案
   def checked(args = {})
     `@check` ||= args[:check]
     `@receiver` ||= args[:receiver]

     `@user` = `@receiver`
     `@link_url` = notification_redirector_url(
-      link: "/users/#{`@user.id`}",
+      link: polymorphic_path(`@check.checkable`),
       kind: Notification.kinds[:checked]
     )
     subject = "[FBC] #{`@check.checkable.user.login_name`}さんの#{`@check.checkable.title`}を#{`@check.action_label`}しました。"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/mailers/activity_mailer.rb` around lines 159 - 169, The checked method
builds a profile URL for `@link_url` but the mail's "この提出物へ" should link to the
submitted work; update the `@link_url` assignment in the checked method to point
to the check's checkable resource (use the path for check.checkable rather than
"/users/#{`@user.id`}") so the mail and the view
(activity_mailer/checked.html.slim) both redirect to the submission; locate the
checked method and replace the current notification_redirector_url(link:
"/users/#{`@user.id`}", kind: Notification.kinds[:checked]) with a link based on
`@check.checkable` (e.g., the checkable's show path or polymorphic path) and keep
the same kind value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/mailers/activity_mailer_test.rb`:
- Around line 422-452: The test "trainee and advisers receive deffierent wording
in their acceptance emails" currently uses loose body assertions; after sending
the trainee email via ActivityMailer.checked(sender: check.sender, receiver:
check.receiver, check:), assert that the trainee email body does NOT include the
adviser-specific prefix (e.g. add assert_no_match(/kensyuさんの/, email.body.to_s)
or equivalent) and keep the existing positive matches for the trainee; then
after sending the adviser email via ActivityMailer.checked(... receiver:
check.receiver.company.advisers[0] ...), keep the existing
assert_match(/kensyuさんの「aptの基礎を覚える」/, email.body.to_s) to ensure the adviser
wording is present. This strengthens the test to guarantee the wording
difference between trainee and adviser emails.

---

Outside diff comments:
In `@app/mailers/activity_mailer.rb`:
- Around line 159-169: The checked method builds a profile URL for `@link_url` but
the mail's "この提出物へ" should link to the submitted work; update the `@link_url`
assignment in the checked method to point to the check's checkable resource (use
the path for check.checkable rather than "/users/#{`@user.id`}") so the mail and
the view (activity_mailer/checked.html.slim) both redirect to the submission;
locate the checked method and replace the current
notification_redirector_url(link: "/users/#{`@user.id`}", kind:
Notification.kinds[:checked]) with a link based on `@check.checkable` (e.g., the
checkable's show path or polymorphic path) and keep the same kind value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ec08712-76ae-48a2-9409-3547eb83cee3

📥 Commits

Reviewing files that changed from the base of the PR and between 9bd0a77 and 7747e29.

📒 Files selected for processing (9)
  • app/mailers/activity_mailer.rb
  • app/mailers/notification_mailer.rb
  • app/models/check_callbacks.rb
  • app/notifiers/activity_notifier.rb
  • app/views/activity_mailer/checked.html.slim
  • test/fixtures/checks.yml
  • test/fixtures/products.yml
  • test/mailers/activity_mailer_test.rb
  • test/system/notification/products_test.rb

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch from 7747e29 to 8f7a3aa Compare March 12, 2026 00: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.

🧹 Nitpick comments (1)
test/mailers/activity_mailer_test.rb (1)

440-443: アドバイザー取得は固定 fixture を使うと安定します。

check.receiver.company.advisers[0] は関連の並び順に依存します。ここは期待値でも固定している users(:senpai) を直接渡した方が、同じ会社の adviser が増えたときも壊れにくいです。

♻️ 修正案
     ActivityMailer.checked(
       sender: check.sender,
-      receiver: check.receiver.company.advisers[0],
+      receiver: users(:senpai),
       check:
     ).deliver_now
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/mailers/activity_mailer_test.rb` around lines 440 - 443, The test uses a
positional association check.receiver.company.advisers[0] which is
order-dependent; replace that with the fixed fixture user users(:senpai) to make
the test stable—update the ActivityMailer.checked call arguments (sender:,
receiver:, check:) to pass receiver: users(:senpai) so the test no longer relies
on advisers ordering and continues to reference the expected adviser fixture.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/mailers/activity_mailer_test.rb`:
- Around line 440-443: The test uses a positional association
check.receiver.company.advisers[0] which is order-dependent; replace that with
the fixed fixture user users(:senpai) to make the test stable—update the
ActivityMailer.checked call arguments (sender:, receiver:, check:) to pass
receiver: users(:senpai) so the test no longer relies on advisers ordering and
continues to reference the expected adviser fixture.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7a192b8b-86c2-4798-9a1a-a04184415cb9

📥 Commits

Reviewing files that changed from the base of the PR and between 7747e29 and 8f7a3aa.

📒 Files selected for processing (4)
  • test/fixtures/checks.yml
  • test/fixtures/products.yml
  • test/mailers/activity_mailer_test.rb
  • test/system/notification/products_test.rb
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/fixtures/checks.yml

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch from 8f7a3aa to 15ee483 Compare March 12, 2026 04:05
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: 1

🧹 Nitpick comments (1)
test/fixtures/checks.yml (1)

53-55: フィクスチャキーのタイポ: procuct75product75

キー名が procuct75_check_komagata となっていますが、product75 のスペルミスです。

ただし、既存のフィクスチャ(lines 29, 33, 37, 41, 45, 49)も同様に procuct というスペルミスのパターンで統一されているため、現時点では一貫性が保たれています。将来的に一括修正することを検討してください。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/fixtures/checks.yml` around lines 53 - 55, The fixture key contains a
typo: rename the key procuct75_check_komagata to product75_check_komagata in the
YAML so it matches the referenced checkable product75 (Product); locate and
update the key name in test/fixtures/checks.yml (and optionally plan a follow-up
to batch-rename the other procuctNN keys for consistency) so tests reference the
correctly spelled product75 identifier.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/mailers/activity_mailer_test.rb`:
- Line 422: Rename the test method name to fix the typo: change the test
declaration string in the test 'trainee and advisers receive deffierent wording
in their acceptance emails' to use "different" instead of "deffierent" so it
reads 'trainee and advisers receive different wording in their acceptance
emails'; update the test name in activity_mailer_test.rb (the test block for
this case) accordingly.

---

Nitpick comments:
In `@test/fixtures/checks.yml`:
- Around line 53-55: The fixture key contains a typo: rename the key
procuct75_check_komagata to product75_check_komagata in the YAML so it matches
the referenced checkable product75 (Product); locate and update the key name in
test/fixtures/checks.yml (and optionally plan a follow-up to batch-rename the
other procuctNN keys for consistency) so tests reference the correctly spelled
product75 identifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d0efe24a-9625-4231-9db0-5b9867984c35

📥 Commits

Reviewing files that changed from the base of the PR and between 8f7a3aa and 15ee483.

📒 Files selected for processing (4)
  • test/fixtures/checks.yml
  • test/fixtures/products.yml
  • test/mailers/activity_mailer_test.rb
  • test/system/notification/products_test.rb
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/fixtures/products.yml
  • test/system/notification/products_test.rb

assert_match(/合格/, email.body.to_s)
end

test 'trainee and advisers receive deffierent wording in their acceptance emails' do
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

テスト名のタイポ: deffierentdifferent

テスト名に綴りミスがあります。

📝 修正案
-  test 'trainee and advisers receive deffierent wording in their acceptance emails' do
+  test 'trainee and advisers receive different wording in their acceptance emails' do
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/mailers/activity_mailer_test.rb` at line 422, Rename the test method
name to fix the typo: change the test declaration string in the test 'trainee
and advisers receive deffierent wording in their acceptance emails' to use
"different" instead of "deffierent" so it reads 'trainee and advisers receive
different wording in their acceptance emails'; update the test name in
activity_mailer_test.rb (the test block for this case) accordingly.

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch from 15ee483 to e259bd7 Compare March 12, 2026 04:15
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.

♻️ Duplicate comments (1)
test/mailers/activity_mailer_test.rb (1)

422-422: ⚠️ Potential issue | 🟡 Minor

テスト名のタイポ: defferentdifferent

テスト名にまだスペルミスが残っています。「defferent」ではなく「different」が正しいです。

📝 修正案
-  test 'trainee and advisers receive defferent wording in their acceptance emails' do
+  test 'trainee and advisers receive different wording in their acceptance emails' do
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/mailers/activity_mailer_test.rb` at line 422, Rename the test method
name to fix the typo: change "trainee and advisers receive defferent wording in
their acceptance emails" to "trainee and advisers receive different wording in
their acceptance emails" in the test definition (the test '...' do block) so the
test name uses the correct spelling "different".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@test/mailers/activity_mailer_test.rb`:
- Line 422: Rename the test method name to fix the typo: change "trainee and
advisers receive defferent wording in their acceptance emails" to "trainee and
advisers receive different wording in their acceptance emails" in the test
definition (the test '...' do block) so the test name uses the correct spelling
"different".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 32adbfea-cf37-400e-8dcb-097bbc5ebf70

📥 Commits

Reviewing files that changed from the base of the PR and between 15ee483 and e259bd7.

📒 Files selected for processing (4)
  • test/fixtures/checks.yml
  • test/fixtures/products.yml
  • test/mailers/activity_mailer_test.rb
  • test/system/notification/products_test.rb
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/fixtures/products.yml
  • test/fixtures/checks.yml

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch 2 times, most recently from 8d01729 to 43ba444 Compare March 12, 2026 06:44
@y-kawahara-gs
Copy link
Copy Markdown
Contributor Author

@matuaya
お疲れ様です!
前回レビューいただいたプルリクと関連した内容だったので、良ければこちらもレビューいただければ助かります🙇‍♂️🙇‍♂️
#9669

@matuaya
Copy link
Copy Markdown
Contributor

matuaya commented Mar 13, 2026

@y-kawahara-gs
お疲れ様です!
レビュー承りました👍
数日ほどお時間いただけたら助かります🙇‍♀️

Copy link
Copy Markdown
Contributor

@matuaya matuaya left a comment

Choose a reason for hiding this comment

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

動作確認しましたのでApproveさせていただきたいと思います!

ちょっと細かいかもしれませんが、もしかしたらkensyu_userの変数名はユーザーオブジェクトが入っているように感じるかもしれないと思いました💦
でもこのままでも全然問題ないと思います🙇‍♀️

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-advisor-notification-on-pass branch from 43ba444 to b359a33 Compare March 19, 2026 01:55
@y-kawahara-gs
Copy link
Copy Markdown
Contributor Author

@matuaya
確かにユーザーオブジェクトが入っているように思える+kensyuよりはtraineeの方がいいと思ったので修正してます!
(kensyuって日本語ですし、変数として使われている部分も全くなかったです)

コミット:b359a33

@y-kawahara-gs
Copy link
Copy Markdown
Contributor Author

@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 5fa0de7 into main Mar 25, 2026
4 checks passed
@komagata komagata deleted the feature/add-advisor-notification-on-pass branch March 25, 2026 05:01
@github-actions github-actions bot mentioned this pull request Mar 25, 2026
27 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