Skip to content

ArticleとWork関連の3クラス分newspaperをActiveSupport::Notificationsに移行#8972

Merged
komagata merged 3 commits intomainfrom
chore/replace-newspaper-with-notifications-in-article-and-work-notifier
Jul 24, 2025
Merged

ArticleとWork関連の3クラス分newspaperをActiveSupport::Notificationsに移行#8972
komagata merged 3 commits intomainfrom
chore/replace-newspaper-with-notifications-in-article-and-work-notifier

Conversation

@hirokiej
Copy link
Copy Markdown
Contributor

@hirokiej hirokiej commented Jul 20, 2025

Issue

概要

以下の3クラスの実装をnewspaperからActiveSupport::Notificationsに置き換えました。

  • ArticleNotifier
  • ArticleNotificationDestroyer
  • WorkNotifier

変更確認方法

  1. chore/replace-newspaper-with-notifications-in-article-and-work-notifierをローカルに取り込む
git fetch origin chore/replace-newspaper-with-notifications-in-article-and-work-notifier
git checkout chore/replace-newspaper-with-notifications-in-article-and-work-notifier
  1. foreman start -f Procfile.devでサーバーを立ち上げます。

それぞれ投稿時に、メールが自動で開かない場合があるので、letter_openerを使って確認をします。


3-1. ArticleNotifierの動作確認

メンターや管理者が書くことができる「ブログ」の作成・更新に対してユーザーに通知を行う機能です。

  1. komagataでログイン。
  • ID: komagata
  • PASS: testtest
  1. 右上の「Me」をクリックし、ブログにアクセスし新規作成をする。
  2. タイトルを「WIPのブログ」にし、本文に任意の文字を入力し「WIP」をクリック。
  3. 再度、新規作成でタイトル「すぐ公開したブログ」、本文に任意の文字を入力し「公開する」をクリック。
  4. hajimeでログイン。
  • ID: hajime
  • PASS: testtest

6.右上の通知に、4で公開した「すぐ公開したブログ」のみがあることを確認する。
7. http://localhost:3000/letter_opener を開き、komagataが「すぐ公開したブログ」を投稿した旨のメールが届いているかを確認する。
i)command + fで、「WIPのブログ」が存在しないこと、「すぐ公開したブログ」のメールが存在することを確認。
8.komagataでログイン。

  • ID: komagata
  • PASS: testtest

9.ブログからWIPにアクセスし、「WIPのブログ」を開き「公開する」をクリック。
10.hajimeでログイン。

  • ID: hajime
  • PASS: testtest

11.右上の通知に、9で公開した「WIPのブログ」があることを確認する。
12. http://localhost:3000/letter_opener を開き、komagataが「WIPのブログ」が投稿した旨のメールが届いているかを確認する。
i)command + fで、「WIPのブログ」のメールが存在することを確認。


3-2. ArticleNotificationDestroyerの動作確認

3-1で扱った「ブログ」の削除に対する通知を削除する機能です。

  1. komagataでログイン。
  • ID: komagata
  • PASS: testtest
  1. 先ほどのブログにアクセスする。
  2. 「WIPのブログ」を開き、記事を削除する。
  3. otameshiでログイン。
  • ID: otameshi
  • PASS: testtest
  1. 右上の通知で「WIPのブログ」がなく、「すぐ公開したブログ」のみが通知にあることを確認。

3-3. WorkNotifierの動作確認

ポートフォリオを作成した際に、メンターと管理者に通知がいく機能です。

  1. otameshiでログイン。
  • ID: otameshi
  • PASS: testtest

2.ポートフォリオの 作品を追加にアクセスする。
3. 任意のタイトル、URL(例: https://google.com)、本文を入力し登録する。
4. komagataでログイン。

  • ID: komagata
  • PASS: testtest

5.右上の通知に、3で登録したポートフォリオに関する通知があることを確認。
6. http://localhost:3000/letter_opener を開き、ポートフォリオ作成に関するメールが届いていることを確認。

※変更前(mainブランチなど)の挙動と、変更後の挙動が同じであることをご確認ください。

Screenshot

※内部的なリファクタリングであり、見た目の変更はないためスクリーンショットはありません。

Summary by CodeRabbit

  • リファクタリング

    • 記事や作品のイベント通知機構を、独自のものからRails標準の通知システムへ切り替えました。
  • その他

    • 内部通知システムの変更に伴い、一部の通知関連処理の引数仕様を更新しました。
    • 通知の購読設定を新しい通知システムに合わせて追加・変更しました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 20, 2025

Walkthrough

Newspaper.publishによるイベント通知の仕組みを、Rails標準のActiveSupport::Notifications.instrumentへ置き換えました。これに伴い、コントローラ内のイベント発行箇所と、各ノーティファイアのコールバックメソッドのシグネチャを変更し、初期化処理での購読設定もActiveSupport::Notificationsに移行しました。

Changes

ファイル/グループ 変更概要
app/controllers/articles_controller.rb, app/controllers/works_controller.rb Newspaper.publishによるイベント発行をActiveSupport::Notifications.instrumentに置換
app/models/article_notifier.rb, app/models/article_notification_destroyer.rb, app/models/work_notifier.rb callメソッドのシグネチャを(payload)から(_name, _started, _finished, _unique_id, payload)へ変更
config/initializers/active_support_notifications.rb ActiveSupport::Notificationsによるイベント購読を追加(記事作成・削除、作品作成)
config/initializers/newspaper.rb Newspaperのイベント購読(記事作成・削除、作品作成)を削除

Sequence Diagram(s)

sequenceDiagram
    participant Controller as Controller
    participant ASNotifications as ActiveSupport::Notifications
    participant Notifier as Notifier/Destroyer

    Controller->>ASNotifications: instrument('article.create', payload)
    ASNotifications-->>Notifier: call(_name, _started, _finished, _unique_id, payload)
    Notifier-->>ASNotifications: (通知処理・副作用実行)
Loading

Estimated code review effort

3 (約45分)

Possibly related PRs

Suggested reviewers

  • komagata

Poem

春風にのせてお知らせピョン
新聞うさぎはおやすみピョン
Railsの鐘が鳴り響く
通知の道も新しく
ぴょんぴょん跳ねてイベント届ける
🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.76.1)
app/controllers/articles_controller.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

app/controllers/works_controller.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

app/models/article_notification_destroyer.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_loader.rb:66:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:160:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:81:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.77.0/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.77.0/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

  • 3 others

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdc60d2 and 112d0a9.

📒 Files selected for processing (7)
  • app/controllers/articles_controller.rb (3 hunks)
  • app/controllers/works_controller.rb (1 hunks)
  • app/models/article_notification_destroyer.rb (1 hunks)
  • app/models/article_notifier.rb (1 hunks)
  • app/models/work_notifier.rb (1 hunks)
  • config/initializers/active_support_notifications.rb (1 hunks)
  • config/initializers/newspaper.rb (0 hunks)
💤 Files with no reviewable changes (1)
  • config/initializers/newspaper.rb
🚧 Files skipped from review as they are similar to previous changes (6)
  • app/controllers/works_controller.rb
  • config/initializers/active_support_notifications.rb
  • app/controllers/articles_controller.rb
  • app/models/article_notifier.rb
  • app/models/work_notifier.rb
  • app/models/article_notification_destroyer.rb
⏰ 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
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hirokiej hirokiej changed the title ArticleとWork系3クラス分newspaperをActiveSupport::Notificationsに移行 ArticleとWork関連の3クラス分newspaperをActiveSupport::Notificationsに移行 Jul 21, 2025
@hirokiej hirokiej marked this pull request as ready for review July 21, 2025 03:58
@hirokiej hirokiej self-assigned this Jul 21, 2025
@hirokiej hirokiej requested a review from smallmonkeykey July 21, 2025 04:18
@hirokiej
Copy link
Copy Markdown
Contributor Author

@smallmonkeykey さん
お疲れ様です!
レビュー依頼です!
現在取り組まれてるissueの3クラス分のものとなります。
急ぎではないので、お願いできないでしょうか🙇?

@smallmonkeykey
Copy link
Copy Markdown
Contributor

@hirokiej
承知しました!
木曜日までにお返事します🙏

Copy link
Copy Markdown
Contributor

@smallmonkeykey smallmonkeykey left a comment

Choose a reason for hiding this comment

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

@hirokiej
とても綺麗に移行できてると思います🙆
動作確認も丁寧に書かれていてわかりやすかったです!
Approveいたします👍

@hirokiej hirokiej force-pushed the chore/replace-newspaper-with-notifications-in-article-and-work-notifier branch from bdc60d2 to 112d0a9 Compare July 23, 2025 18:00
@hirokiej
Copy link
Copy Markdown
Contributor Author

@smallmonkeykey さん
ご確認ありがとうございます🙇

@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 9b7e943 into main Jul 24, 2025
5 checks passed
@komagata komagata deleted the chore/replace-newspaper-with-notifications-in-article-and-work-notifier branch July 24, 2025 06:15
@github-actions github-actions bot mentioned this pull request Jul 24, 2025
87 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