-
Notifications
You must be signed in to change notification settings - Fork 75
retirement_createとtraining_completion_createの呼び出しをNewspaperからActiveSupport::Notificationsに移行 #9219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c9417ca
365669b
ea1728b
ef309cd
5998f3c
076152a
b0f0844
33c51f7
60a0ae5
54ded0f
7a29328
e1c9eab
dc98428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.configuration.after_initialize do | ||
| unfinished_data_destroyer = UnfinishedDataDestroyer.new | ||
| Newspaper.subscribe(:retirement_create, unfinished_data_destroyer) | ||
| Newspaper.subscribe(:training_completion_create, unfinished_data_destroyer) | ||
|
|
||
| times_channel_destroyer = TimesChannelDestroyer.new | ||
| Newspaper.subscribe(:retirement_create, times_channel_destroyer) | ||
| Newspaper.subscribe(:training_completion_create, times_channel_destroyer) | ||
|
|
||
| Newspaper.subscribe(:came_comment_in_talk, CommentNotifierForAdmin.new) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'test_helper' | ||
|
|
||
| class UnfinishedDataDestroyerTest < ActiveSupport::TestCase | ||
| setup do | ||
| @payload = { user: users(:kimura) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setupがシンプルで、 |
||
| end | ||
|
|
||
| test '#call deletes user wip reports and unchecked products and resets career_path' do | ||
| user = @payload[:user] | ||
| user.update!(career_path: 1) | ||
|
|
||
| 3.times do |i| | ||
| Report.create!( | ||
| user:, | ||
| title: "wipの日報#{i}", | ||
| description: 'テスト日報', | ||
| wip: true, | ||
| reported_on: Date.current - i | ||
| ) | ||
| end | ||
|
|
||
| practices = Practice.where.not(id: user.products.pluck(:practice_id)).take(3) | ||
| practices.each do |practice| | ||
| Product.create!( | ||
| user:, | ||
| practice:, | ||
| body: '提出物', | ||
| wip: false | ||
| ) | ||
| end | ||
|
Comment on lines
+24
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| UnfinishedDataDestroyer.new.call(nil, nil, nil, nil, @payload) | ||
|
|
||
| assert_equal 0, Product.unchecked.where(user:).count | ||
| assert_equal 0, Report.wip.where(user:).count | ||
| assert_equal 'unset', user.reload.career_path | ||
| end | ||
|
Comment on lines
+6
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
現在、
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| test 'does not delete other users wip report and unchecked product' do | ||
| other_user_unchecked_product = products(:product1) | ||
| other_user_wip_report = reports(:report9) | ||
|
|
||
| UnfinishedDataDestroyer.new.call(nil, nil, nil, nil, @payload) | ||
|
|
||
| assert Product.exists?(other_user_unchecked_product.id) | ||
| assert Report.exists?(other_user_wip_report.id) | ||
| end | ||
|
|
||
| test 'does not delete checked product or non-wip report' do | ||
| checked_product = products(:product2) | ||
| non_wip_report = reports(:report24) | ||
|
|
||
| UnfinishedDataDestroyer.new.call(nil, nil, nil, nil, @payload) | ||
|
|
||
| assert Product.exists?(checked_product.id) | ||
| assert Report.exists?(non_wip_report.id) | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
ActiveSupport::Notifications購読者の署名に正しく適合しています。
メソッド署名が
ActiveSupport::Notificationsのコールバック署名(name, started, finished, id, payload)に更新されています。未使用の4つのパラメータにアンダースコアプレフィックスが付けられており、適切です。メソッド本体のロジック(payload[:user]の抽出とクリーンアップ処理)は変更されていません。コーディングガイドラインに基づき、モデルメソッドには対応するユニットテストが必要です。以下のスクリプトを実行して、
UnfinishedDataDestroyerのテストが存在し、新しい署名に対応していることを確認してください:🏁 Script executed:
Length of output: 116
以下のスクリプトで
spec/ディレクトリ内のテストファイルとUnfinishedDataDestroyer#call呼び出しを確認してください。🏁 Script executed:
Length of output: 224
UnfinishedDataDestroyerに対応するテストが存在しません。
ActiveSupport::Notificationsのコールバック署名変更(call(name, started, finished, id, payload))を検証するユニットテストが
test/およびspec/内に見当たりません。新しい署名に対応したテストを追加してください。🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストの追加しました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 659
@matuaya さん、テストの追加をありがとうございます!確認しました。
test/models/unfinished_data_destroyer_test.rbのテストは適切に実装されています:✅ 新しい5パラメータ署名を正しく使用
call(nil, nil, nil, nil, payload)で ActiveSupport::Notifications のコールバック署名に対応✅ すべての処理を検証
career_pathのリセットテストケースが網羅的で、実装の変更を適切に検証しています。
🧬 Code Graph Analysis Results
<possibly_relevant_code_snippets>
app/controllers/reports_controller.rb (lines 24-30)
app/models/times_channel_destroyer.rb (lines 3-16)
🧠 Learnings used
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!