Skip to content

ローカル環境で通らなかったテストnotify comment and checkを通るように修正#9027

Merged
komagata merged 15 commits intomainfrom
chore/fix-notify_comment_and_check-test
Aug 15, 2025
Merged

ローカル環境で通らなかったテストnotify comment and checkを通るように修正#9027
komagata merged 15 commits intomainfrom
chore/fix-notify_comment_and_check-test

Conversation

@tyrrell-IH
Copy link
Copy Markdown
Contributor

@tyrrell-IH tyrrell-IH commented Aug 13, 2025

Issue

概要

issueの通りです。テストが通るように修正しました。
修正のポイントは以下の通りです。

  • 新規作成の日報がDBに保存される前にReport.last.idを実行すると違う日報のidを返してしまうので、日報の保存を待つ処理を追加
  • visit_with_authを使ってログイン状態を切り替える際に、logoutを利用し明示的にログインセッションを破棄することでログイン状態を切り替える
  • visit等で画面を移動する際に、assert_selectorを使って移動先のDOMが構築されるのを待つ

変更確認方法

  1. chore/fix-notify_comment_and_check-testをローカルに取り込み、ブランチを切り替える。
git fetch origin chore/fix-notify_comment_and_check-test
git checkout chore/fix-notify_comment_and_check-test
  1. テストが通ることを確認する。
bin/rails test test/system/notifications_test.rb:256

Screenshot

内部的な修正のため無し。

Summary by CodeRabbit

  • テスト
    • 日報作成フローのE2Eテストを安定化(作成完了を待機するロジックを追加し、「日報作成」見出しの表示を検証)
    • コメント通知テストを改善(ログイン直後のダッシュボード確認、ページ見出しの検証、投稿内容と通知文言の明示的チェック、不要な遷移の削除)
    • 全体としてテストの信頼性と再現性を向上し、フレークを低減

Summary by CodeRabbit

  • テスト
    • レポート作成後にページヘッダーの表示を確認するアサーションを追加。
    • 作成レポートの参照をデータベース参照から画面遷移(URL)ベースに変更し、遷移先の整合性を検証する保護を追加。
    • 通知確認シナリオを見直し、ダッシュボード/詳細ページのヘッダー確認やルート経由の遷移を導入。
    • クロスユーザーでの通知内容確認とE2Eテストの安定性を向上。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 13, 2025

Walkthrough

テストヘルパーで作成後の画面ヘッダ検証を追加し、作成済レポートIDをDB参照から現在のパスの正規表現抽出へ変更。通知システムテストは report 参照を report_id に切替え、ダッシュボード確認とルート経由での通知検証フローに更新。

Changes

Cohort / File(s) Summary
レポート作成ヘルパー
test/supports/report_helper.rb
新規作成後のヘッダ存在を確認(h2.page-header__title '日報作成'、投稿後は h2.page-header__title '日報編集' または h1.page-content-header__title タイトル)。作成レポートIDを Report.last.id から current_path の正規表現抽出へ変更し、パスマッチ時にアサート追加。
通知システムテスト
test/system/notifications_test.rb
テスト内で report オブジェクト参照を report_id に変更。ダッシュボードヘッダ確認を追加し、報告ページでタイトル検証。コメント後の別ユーザー確認手順をログアウト→ルートへ移動→通知開封の流れに変更。

Sequence Diagram(s)

sequenceDiagram
  actor Tester as テスト
  participant Browser
  participant App

  Tester->>Browser: create_report(title, description, wip)
  Browser->>App: POST /reports
  App-->>Browser: Redirect /reports/{id} or /reports/{id}/edit
  Browser-->>Tester: current_path を取得
  Tester->>Tester: path から report_id を抽出

  Tester->>Browser: Visit /reports/{report_id}
  Browser->>App: GET /reports/{report_id}
  App-->>Browser: レポートページ(ヘッダ/タイトル表示)

  Tester->>Browser: Post comment
  Browser->>App: POST /reports/{report_id}/comments

  Tester->>Browser: Logout -> Visit /
  Browser->>App: GET /
  Tester->>Browser: Open notifications
  Browser->>App: GET /notifications
  App-->>Browser: 通知を表示
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Suggested reviewers

  • komagata

Poem

ぴょんと走ってパスを覗けば
数字がチラリと顔を出すよ
ダッシュ見てコメント鳴れば
ルートを辿り通知を覗く
うさぎは今日もテストを跳ねる 🐇✨

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)
test/supports/report_helper.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.79.2/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/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.79.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:162:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:82:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 27a87d0 and ce8ce9d.

📒 Files selected for processing (1)
  • test/supports/report_helper.rb (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/supports/report_helper.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
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/fix-notify_comment_and_check-test

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@tyrrell-IH tyrrell-IH force-pushed the chore/fix-notify_comment_and_check-test branch from 6b9b512 to 7929cb4 Compare August 13, 2025 06:07
@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

1 similar comment
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ryufuta
Copy link
Copy Markdown
Contributor

ryufuta commented Aug 13, 2025

@tyrrell-IH
システムテストのことはよく知らなかったので勉強になりますし、サポートして下さって大変ありがたいです🙏

私の環境でもこのテストを10回以上実行しましたが、すべてパスしましたので、問題自体は修正できていると思います。

ただ、保守性や実行時間、テストの安定性の観点からwait_for_report_createdメソッドの処理のみ改善が必要と思いました。
その他の修正箇所は大丈夫だと思います。

駒形さんに確認したところ、sleepを使用するのは可能な限り避けたいので、リリースを急ぐよりも多少時間をかけてでも修正してほしいとのことでした。

修正案は考えつけていないのですが、私が試したこと、修正の未熟なアイデアを共有します。
(時間があれば今日もう少し考えてみます)

試してダメだったこと

create_reportメソッド内の

wait_for_report_created(before_count, timeout: 5)

assert_selector 'h1.page-content-header__title', text: title

に変更(日報提出ボタンをクリック後、その日報のページに遷移するのでそれを待機する)してみましたが、flakyなので却下 (DB保存を待機できず別のユーザーの日報のidを取得することがある)

(追記)
flakyな理由が不正確でした。
エラーの原因がわかっていません💦
実際のエラーログとスクショを添付します。

❯ bin/rails test test/system/notifications_test.rb:256
Running via Spring preloader in process 21099
Run options: --seed 32321

# Running:

[Screenshot Image]: /Users/myname/Documents/FjordBootCamp/bootcamp/tmp/screenshots/failures_test_notify_comment_and_check.png
E

Error:
NotificationsTest#test_notify_comment_and_check:
ActionView::Template::Error: undefined method `variant' for #<ActiveStorage::Attached::One:0x00000001375e5d98 @name="avatar", @record=#<User id: 888299165, login_name: "yameo", tag_list: nil>>
    app/views/api/user_icon_urls/index.json.jbuilder:2
    app/views/api/user_icon_urls/index.json.jbuilder:1


rails test test/system/notifications_test.rb:256


[Minitest::CI] Generating test report in JUnit XML format...


Finished in 13.443027s, 0.0744 runs/s, 0.2976 assertions/s.
1 runs, 4 assertions, 0 failures, 1 errors, 0 skips
image

検討中の案

実装は未着手でアイデア段階です🙇🏻‍♂️

create_reportメソッドの引数に日報作成者を一意に識別できる情報(ログインユーザー名など)を追加します。
ユーザーと日報のタイトルのペアはユニークなので、この変更によりcreate_reportメソッド内で作成した日報のIDをReport.find_byメソッド等で明示的に取得できるのではと考えています。
(本題とそれますが、Report.last.idでIDを取得するのは意図がわかりづらいですし、並列実行した際にバグりそうと思いました)

懸念点は

  • DB保存前にReport.find_byメソッドを呼ばれることがあるかもしれないのでflakyの解決にならない
    • その場合でも別の日報を返すよりエラーを返す方がわかりやすいというメリットはある
    • エラーが発生したら見つかるまでループするとかできるかも
  • メソッドの引数を変更することで他のテストの修正も必要になる

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

tyrrell-IH commented Aug 13, 2025

@ryufuta
wait_for_report_created件、駒形さんにご確認いただきありがとうございました🙏
sleepを使わないように修正しました!

修正方針1

click_button(wip ? 'WIP' : '提出')を押した後、

assert(
  page.has_selector?('h1.page-content-header__title', text: title, wait: 5) || # 提出の場合の移動先
    page.has_selector?('h2.page-header__title', text: '日報編集') # wipの場合の移動先
)

でDOM構築を待つ
(/reports/report_id/(edit)に移動することをもって日報がDBに保存されたことを確認する。)

修正方針2

current_path.match(%r{^/reports/(\d+)(/edit|)$})[1].to_iでreport作成後のcurrent_pathからidを取得する

試してダメだったことの件について

私の環境でwait_for_report_created(before_count, timeout: 5)の代わりにassert_selector 'h1.page-content-header__title', text: title等を置いてもエラーは発生しませんでした。

エラーが発生しないこと、assert_selector 'h1.page-content-header__title', text: title等だと/reports/report_id/(edit)のDOM構築を待つことでDBの保存も待つことができること、の点でこの方法を採用しました。

そもそもryufuta さんのエラー内容とassert_selector 'h1.page-content-header__title', text: titleとの関係については少し疑問があって、assertionの結果が1 runs, 4 assertions, 0 failures, 1 errors, 0 skipsとなっているので、ryufutaさんが他にアサーションを追加していなければ、4つ目のアサーション
つまりassert_selector 'h1.page-content-header__title', text: 'コメントと'(263行目)の箇所以降でエラーが発生したのではと思います。

添付いただいた画像からもkomagataによるコメントがあるので、create_reportは実行された後であり、create_reportassert_selector 'h1.page-content-header__title', text: titleとは直接関係ないのではと思いました。

以上より、なぜryufutaさんの環境でそのエラーが発生したのかが気になります🤔
また、状況が改善されていないとしたら私の修正案でもエラーが出てしまうと思うので、今一度動作のご確認をいただきたいです🙏

report_idを取得する方法

確かにReport.last.idでid取得するのは嫌な感じしますね。。特に並列処理時のバグはありそうだと思いました。

修正案として、当初

create_reportメソッドの引数に日報作成者を一意に識別できる情報(ログインユーザー名など)を追加します。

このやり方は結構いいなと思ったのですが、create_reportが以下の箇所で使われていて

grep -R "create_report" test/
test/supports/report_helper.rb:  def create_report(title, description, wip)
test/system/notification/mention_test.rb:      create_report('メンション通知が送信されるかのテスト', description, false)
test/system/notification/reports_test.rb:    create_report('初日報です', '初日報の内容です', false)
test/system/notification/reports_test.rb:        report_id = create_report(title, description, true)
test/system/notifications_test.rb:    report = create_report 'コメントと', '確認があった', false

create_reportの引数を変えることでそれらのテストの動作確認も必要になるので、今回はちょっと避けたいと思いました。

あまりいい方法は思いつかなかったのですが、日報作成後に/reports/report_id/(edit)に移動するので、current_path.match(%r{^/reports/(\d+)(/edit|)$})[1].to_iでそのcurrent_pathからidを取得することにしました。

ただ、これも

  • reports/create(update)アクションの動作(@reportにリダイレクトする)に依存
  • current_path.match(%r{^/reports/(\d+)(/edit|)$})[1].to_iは何の値を返すか分かりづらい?結局コメントが必要かも、、

という点でいい方法なのかどうかあまり自信はなく、場合によっては再度駒形さんに相談することになるかもしれません。

この辺もご意見いただきたいです〜

@tyrrell-IH tyrrell-IH changed the title ローカル環境で通らなかった'notify comment and check'テストを通るように修正 ローカル環境で通らなかったテストnotify comment and checkを通るように修正 Aug 13, 2025
@tyrrell-IH tyrrell-IH force-pushed the chore/fix-notify_comment_and_check-test branch from cae8f04 to 696e06a Compare August 13, 2025 18:48
@ryufuta ryufuta self-requested a review August 13, 2025 23:50
@ryufuta
Copy link
Copy Markdown
Contributor

ryufuta commented Aug 14, 2025

@tyrrell-IH
修正とPR作成ありがとうございます!(ご無理なさらずに🙏)

結論から言うと、これで大丈夫だと思います。
以下、詳細を書きますが、特に議論したいことがなければ、このまま駒形さんにレビュー依頼していただいて良いと思います。

試してダメだったことの件について

最新のブランチをpullして私の環境でもテストを実行してみました。
1回目は全く同じエラーが再発したのですが、ターミナルを再起動してから実行し直したところ20回連続でパスしました。
原因不明ですが、私の環境の一時的な問題だったのかもしれないので、コード修正としては現状でOKかなと判断しました。

エラーの内容と今回の修正が関係なさそうというのはご指摘の通りだと思います。
(当初早とちりしていましたがスクショを見て気づいて訂正しました💦 assert文の実行回数もきちんと確認した方が良いということ、勉強になります🙏)

エラーメッセージを改めて見ると、yameoのアバター画像を取得する箇所でエラーになっています。
作成した日報のページにはyameoのアイコン表示は存在しないはずなので、おそらく267行目でhatsunoのダッシュボードに遷移する際に「最新のみんなの日報」欄あたりにyameoのアイコンを表示しようとして失敗しているのかと推測しました。
いずれにせよ、今回の修正とは別の原因だと思うので、今後私の環境で再発した際に別のissueで対応するということで良いと判断しました。

report_idを取得する方法

こちら、pathからidを取得する今の方法の方が良いと思うので大丈夫です。(思い付かなかった。勉強になります)
ご指摘しただいた修正範囲の他に以下が理由です。

  • DB保存前に検索しても見つからないので、結局見つかるまでループする処理を書くことになり元のsleepするコードと大差ない
  • DB検索すると時間がかかる

リダイレクトする動作に依存する点について。
システムテストではUIに依存するのは仕方ないのかなと思いました(実際はどうなのだろう🤔)
現状assert_selectorなどを使用している箇所も似たような理由でUIに依存しているので。

正規表現を使用している点について。
他に良い方法が思い付いてないので何ともという感じです🙇🏻‍♂️
一旦これでレビュー依頼して意見をいただくのが良いかなと思いました。

@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

tyrrell-IH commented Aug 14, 2025

@ryufuta
ご確認ありがとうございました!

エラーメッセージを改めて見ると、yameoのアバター画像を取得する箇所でエラーになっています。
作成した日報のページにはyameoのアイコン表示は存在しないはずなので、おそらく267行目でhatsunoのダッシュボードに遷移する際に「最新のみんなの日報」欄あたりにyameoのアイコンを表示しようとして失敗しているのかと推測しました。
いずれにせよ、今回の修正とは別の原因だと思うので、今後私の環境で再発した際に別のissueで対応するということで良いと判断しました。

なんとなくエラーの内容的に今回のwebp(avatar_url)に絡みそうかなと思ったので、再発したらまた教えてください🙏

不安な点については駒形さんにレビュー出す時に伝えたいと思います!

@tyrrell-IH tyrrell-IH marked this pull request as ready for review August 14, 2025 04:24
@github-actions github-actions bot requested a review from komagata August 14, 2025 04:24
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/system/notifications_test.rb (1)

261-271: ジョブ実行範囲の最小化+パスヘルパーの利用で可読性・意図の明確化

  • perform_enqueued_jobs は通知生成に関わる操作(コメント/確認OK)に限定すると意図が明確で副作用も減らせます。その後のログアウト・通知UIの確認はジョブ実行に関係ないためブロック外へ。
  • 文字列連結のパス指定は、report_path/root_path を使うとルーティング変更に強くなります。
-    perform_enqueued_jobs do
-      visit_with_auth "/reports/#{report_id}", 'komagata'
-      assert_selector 'h1.page-content-header__title', text: 'コメントと'
-      fill_in 'new_comment[description]', with: 'コメントと確認した'
-      click_button '確認OKにする'
-      logout
-      visit_with_auth '/', 'hatsuno'
-      assert_selector 'h2.page-header__title', text: 'ダッシュボード'
-      find('.header-links__link.test-show-notifications').click
-      assert_text 'hatsunoさんの日報「コメントと」にkomagataさんがコメントしました。'
-    end
+    perform_enqueued_jobs do
+      visit_with_auth report_path(report_id), 'komagata'
+      assert_selector 'h1.page-content-header__title', text: 'コメントと'
+      fill_in 'new_comment[description]', with: 'コメントと確認した'
+      click_button '確認OKにする'
+    end
+    logout
+    visit_with_auth root_path, 'hatsuno'
+    assert_selector 'h2.page-header__title', text: 'ダッシュボード'
+    find('.header-links__link.test-show-notifications').click
+    assert_text 'hatsunoさんの日報「コメントと」にkomagataさんがコメントしました。'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 30a74a9 and 696e06a.

📒 Files selected for processing (2)
  • test/supports/report_helper.rb (2 hunks)
  • test/system/notifications_test.rb (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.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/supports/report_helper.rb
  • test/system/notifications_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/report_helper.rb
  • test/system/notifications_test.rb
🧠 Learnings (1)
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
PR: fjordllc/bootcamp#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:

  • test/supports/report_helper.rb
🧬 Code Graph Analysis (1)
test/system/notifications_test.rb (1)
test/supports/report_helper.rb (1)
  • create_report (4-23)
🔇 Additional comments (2)
test/supports/report_helper.rb (1)

6-6: 新規ページのDOM構築待ちの追加は妥当

visit new_report_path 直後にヘッダの存在を待つことで、以降の操作の安定性が上がっています。

test/system/notifications_test.rb (1)

258-259: ダッシュボード表示の待機追加は適切

ログイン直後のヘッダを待つことで、その後の作業(レポート作成)を安定させています。意図に合致しており問題ありません。

@tyrrell-IH tyrrell-IH force-pushed the chore/fix-notify_comment_and_check-test branch from 696e06a to 27a87d0 Compare August 14, 2025 07:06
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

♻️ Duplicate comments (1)
test/supports/report_helper.rb (1)

17-21: OR待機の除去とwIP/提出での明示的なassert分岐はGood

has_selector? のOR待機から assert_selector の分岐へ置き換えられており、失敗時の診断性と安定性が向上しています。過去コメントの提案どおりで問題ありません。

🧹 Nitpick comments (3)
test/supports/report_helper.rb (3)

20-20: 提出時の見出し待機にも明示的なwaitを付与してフレーク低減

wip側に wait: 5 を指定しているのに対し、提出側は未指定です。環境差やCI負荷時の遅延を考慮して、提出側にも wait を付けておくと安定します。

-      assert_selector 'h1.page-content-header__title', text: title
+      assert_selector 'h1.page-content-header__title', text: title, wait: 5

6-6: 新規作成ページのヘッダ確認にもwaitを指定して一貫性を確保

初期表示もDOM構築が遅れる可能性があるため、他の箇所と同様に wait を付与するのが無難です。

-    assert_selector 'h2.page-header__title', text: '日報作成'
+    assert_selector 'h2.page-header__title', text: '日報作成', wait: 5

24-26: ID抽出は安全になっていてOK。変数名をMatchDataに即したものへ微調整

処理自体は安全で正しいです。変数名が「id」を連想させるため、実体(MatchData)に即した名前へ変えると読みやすくなります。

-    report_match_id = current_path.match(%r{^/reports/(\d+)(/edit)?$})
-    assert report_match_id, "Unexpected path after creating report: #{current_path}"
-    report_match_id[1].to_i
+    path_match = current_path.match(%r{^/reports/(\d+)(/edit)?$})
+    assert path_match, "Unexpected path after creating report: #{current_path}"
+    path_match[1].to_i
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 696e06a and 27a87d0.

📒 Files selected for processing (2)
  • test/supports/report_helper.rb (2 hunks)
  • test/system/notifications_test.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/system/notifications_test.rb
🧰 Additional context used
📓 Path-based instructions (2)
**/*.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/supports/report_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/supports/report_helper.rb
🧠 Learnings (1)
📚 Learning: 2025-07-23T20:31:13.856Z
Learnt from: jun-kondo
PR: fjordllc/bootcamp#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:

  • test/supports/report_helper.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

@ryufuta
Copy link
Copy Markdown
Contributor

ryufuta commented Aug 14, 2025

@tyrrell-IH
ご対応ありがとうございます!
(自分がレビュアーで良いのかわかりませんが)Approveしました🙆🏻‍♂️

@komagata
お忙しいところ恐縮ですが、レビューをお願いします🙏

click_button(wip ? 'WIP' : '提出')

if wip
assert_selector 'h2.page-header__title', text: '日報編集', wait: 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

下記でデフォルト15秒にしているので逆に短くしているように思いますが、こちらは意図通りでしょうか。

https://github.com/fjordllc/bootcamp/blob/main/test/test_helper.rb#L14

Copy link
Copy Markdown
Contributor Author

@tyrrell-IH tyrrell-IH Aug 15, 2025

Choose a reason for hiding this comment

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

@komagata
意図して書きました、

wipがfalseの場合

if wip
  assert_selector 'h2.page-header__title', text: '日報編集', wait: 5

の判定(提出ボタンを押した場合には全てこの判定を通る)に15秒待つのは長すぎると思いました。

waitを3秒とか5秒とか10秒とかに変更しつつ、30回くらいテストを回してみて現状確実にテストが通る最低の時間が5秒という感じです。

Copy link
Copy Markdown
Contributor Author

@tyrrell-IH tyrrell-IH Aug 15, 2025

Choose a reason for hiding this comment

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

@komagata
すいません、間違えました。
上記の話は修正する前の実装の話でした。
修正前はorでどのアサーションを使うか要素をアサーションの対象にするか分岐させていて、その左辺の処理を待機するのに5秒の最低ラインを考えた、という話でした。
389a181

現状はif文でwipかどうかを事前に判定しているので、wait: 5の個別の設定は不要でしたので修正します。

@tyrrell-IH tyrrell-IH force-pushed the chore/fix-notify_comment_and_check-test branch from 27a87d0 to ce8ce9d Compare August 15, 2025 02:42
@tyrrell-IH
Copy link
Copy Markdown
Contributor Author

tyrrell-IH commented Aug 15, 2025

@komagata
修正しましたのでご確認ください。
修正箇所は指摘のあったwait: 5の削除
commit: 40c20a9

とCodeRabbitよりNitPickで指摘のあった事項

24-26: ID抽出は安全になっていてOK。変数名をMatchDataに即したものへ微調整

に関する修正も行なっています。
commit: ce8ce9d

また改めてこのPRを作成した経緯について説明します。
当初@ryufutaさんの方でtest/system/notifications_test.rb:256がエラーとなる原因を調べていただいていましたが、私が上記テストのエラーを概ね解明かつ対処するためのコードの修正ができそうだったので、私の方でPRを作成する旨を申し出ました。

ただ、PRの内容の精査、descriptionの作成、レビューに出すタイミング、レビューへの対応が、私の時間的な制約上管理できない可能性があったため、ryufutaさんへ「自由にコミットしたり、好きにしていいです」という合意のもと叩き台としてのPRを作成しました。

結果的には今回のPRは私が実装の全てを担っているので、私がPR作成者、ryufutaさんがレビュアーとなっていますが、私としては共同でPRを作成しているという認識なので、私が対応できない時はryufutaさんがレビューの対応、再レビュー依頼をすることになると思いますので、その旨ご了承ください🙏

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 2b6bb5b into main Aug 15, 2025
8 checks passed
@komagata komagata deleted the chore/fix-notify_comment_and_check-test branch August 15, 2025 04:53
@github-actions github-actions bot mentioned this pull request Aug 15, 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