Skip to content

プラクティスに理解度テスト機能を追加#10241

Open
komagata wants to merge 9 commits into
mainfrom
codex/practice-quizzes
Open

プラクティスに理解度テスト機能を追加#10241
komagata wants to merge 9 commits into
mainfrom
codex/practice-quizzes

Conversation

@komagata

@komagata komagata commented Jun 27, 2026

Copy link
Copy Markdown
Member

概要

  • プラクティスごとに単一選択・複数選択の理解度テストを設定できるようにしました。
  • mentor 管理画面で理解度テストと問題・選択肢・正解・解説を管理できるようにしました。
  • 公開中の理解度テストに合格するまで、そのプラクティスを修了できないようにしました。
  • 不合格後1時間の再受験制限と、合格後の正解・解説表示を追加しました。

確認

  • mise exec -- ./bin/lint
  • mise exec -- bin/rails test test/models/practice_quiz_test.rb test/models/practice_quiz_question_test.rb test/models/practice_quiz_attempt_test.rb test/models/learning_status_updater_test.rb test/integration/practice_quizzes_test.rb test/integration/mentor/practice_quizzes_test.rb test/system/practices_test.rb test/models/practice_test.rb test/models/product_test.rb
  • mise exec -- bin/rails test:all(2877 runs、変更範囲外の system test 2件が失敗。各失敗テストを単体再実行して通過)

Closes #10240

Summary by CodeRabbit

  • New Features
    • プラクティスに「理解度テスト」を追加。メンターは問題・選択肢を作成/公開でき、受講者は受験して合否と解説・正誤を確認可能。
    • クールダウン付きの再受験制御と、回答状態に応じた画面表示を実装。タブ/導線、管理画面、問題管理UI、スタイルも追加。
  • Bug Fixes
    • APIの学習更新を厳格化し、不正な状態指定や完了条件未充足時は 422 で返却。
    • 合否判定の完了可否ロジックをクイズ要件に連動。
  • Tests
    • 受験〜合否〜完了判定、クールダウン、メンター作成フローの結合/モデルテストを追加。

Flakewatch Report

Flakewatch Report

Review App

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

理解度テストの永続化、受験、修了判定、メンター管理画面、関連テストとフィクスチャが追加されています。

Changes

プラクティス理解度テスト

Layer / File(s) Summary
データモデルと公開条件
db/migrate/*create_practice_quizzes*.rb, db/schema.rb, app/models/practice.rb, app/models/practice_quiz.rb, app/models/practice_quiz_question.rb, app/models/practice_quiz_choice.rb, app/models/practice_quiz_answer.rb, db/seeds.rb
PracticeQuiz と設問・選択肢・回答の関連、公開条件、正誤判定、削除制御が追加され、対応するテーブル定義も作成されました。
受験結果と修了判定
app/models/practice_quiz_attempt.rb, app/models/learning_status_updater.rb, app/controllers/api/practices/learning_controller.rb, test/models/practice_quiz_attempt_test.rb, test/models/learning_status_updater_test.rb, test/integration/practice_quizzes_test.rb
PracticeQuizAttempt の採点、1時間クールダウン、Learning.status 更新、complete 拒否条件が追加され、関連テストが追加されました。
受講生向け導線
app/controllers/practices/practice_quiz_controller.rb, app/controllers/practices/practice_quiz/attempts_controller.rb, app/helpers/page_tabs/practices_helper.rb, app/views/practices/practice_quiz/show.html.slim, app/views/practices/show.html.slim, config/routes.rb, app/assets/stylesheets/application.css, app/assets/stylesheets/application/blocks/practice-quiz/_practice-quiz.css, db/fixtures/practice_quiz_*.yml, test/integration/practice_quizzes_test.rb, db/fixtures/practices.yml
プラクティス詳細からクイズ表示と受験投稿への導線が追加され、合格・再受験待ち・未合格の表示が分岐します。
メンター管理画面
app/controllers/mentor/practices/practice_quiz_controller.rb, app/controllers/mentor/practices/practice_quiz/questions_controller.rb, app/views/mentor/practices/_mentor_practices.html.slim, app/views/mentor/practices/practice_quiz/*.slim, app/views/mentor/practices/practice_quiz/questions/*.slim, config/routes/mentor.rb, test/integration/mentor/practice_quizzes_test.rb
クイズ本体と問題の新規作成・編集・削除、公開切替、ネストした選択肢編集の画面とルートが追加されました。
フィクスチャとシード順序
test/fixtures/practice_quiz_answers.yml, test/fixtures/practice_quiz_attempts.yml, test/fixtures/practice_quiz_choices.yml, test/fixtures/practice_quiz_questions.yml, test/fixtures/practice_quizzes.yml
理解度テスト用の fixtures が追加されました。

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested reviewers: okuramasafumi

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 概要と確認はあるものの、テンプレート必須の「Issue」「変更確認方法の手順」「Screenshot(変更前/後)」が欠けています。 Issue番号、ローカル取り込み後の確認手順を具体化し、変更前/後のスクリーンショット欄を追加してください。
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 変更内容の中心である理解度テスト追加を端的に表しています。
Linked Issues check ✅ Passed #10240】理解度テストの作成・受験・再受験制限・完了制御・管理画面の要件がおおむね満たされています。
Out of Scope Changes check ✅ Passed 目的外の大きな変更は見当たらず、理解度テスト機能の追加に収まっています。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/practice-quizzes

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.

@github-project-automation github-project-automation Bot moved this to 作業中 in bootcamp Jun 27, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

🧹 Nitpick comments (3)
db/migrate/20260627120618_create_practice_quiz_attempts.rb (1)

3-10: 🚀 Performance & Scalability | 🔵 Trivial

再受験クールダウン/合格判定クエリ向けに複合インデックスの追加を検討してください。

再受験ロックアウト判定や合格済み判定では、ユーザーとクイズの組み合わせで最新の受験 (submitted_at) を引く問い合わせが繰り返し発生する想定です。t.references が作る単一カラムのインデックスだけでは効率が落ちる可能性があるため、(practice_quiz_id, user_id, submitted_at) の複合インデックスを検討するとよいです。

♻️ 追加例
       t.datetime :submitted_at, null: false
       t.boolean :passed, null: false, default: false

       t.timestamps
+
+      t.index [:practice_quiz_id, :user_id, :submitted_at]
     end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@db/migrate/20260627120618_create_practice_quiz_attempts.rb` around lines 3 -
10, The practice_quiz_attempts table only has single-column indexes from the
references, but the cooldown and passed-check queries will repeatedly filter by
practice_quiz_id and user_id and sort or look up by submitted_at. Add a
composite index on practice_quiz_attempts using the create_table block in the
migration so the schema supports those access patterns efficiently; use the
existing practice_quiz_attempts table definition as the place to introduce the
new index alongside the references.
test/integration/practice_quizzes_test.rb (2)

43-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

再受験ロック中の案内文を確認したほうがよいです。

ここでは再投稿が拒否されることしか検証しておらず、「次に受験可能な時刻を表示する」要件が未カバーです。リダイレクト先の flash か本文に次回時刻が出ることまで押さえると、仕様の抜け漏れを防げます。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/practice_quizzes_test.rb` around lines 43 - 65, The
retry-lock test for PracticeQuiz attempts only checks that the second submission
is rejected, but it does not cover the expected user guidance showing when the
quiz can be taken again. Update the test around
practice_practice_quiz_attempts_path and practice_practice_quiz_path to assert
that the redirect response includes the next available attempt time in either
the flash message or rendered content, alongside the existing no-new-attempt
check.

6-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

合格後の表示要件まで検証しておきたいです。

このケースは合格後のリダイレクトまでしか見ていないので、「正答・解説・合格状態が見える」という要件の退行を拾えません。follow_redirect! して表示内容まで固定しておくと安心です。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/practice_quizzes_test.rb` around lines 6 - 30, The practice
quiz flow currently only asserts the redirect after a passing attempt, so it can
miss regressions in the post-pass UI. Update the integration test in
practice_quizzes_test around practice_practice_quiz_attempts_path to
follow_redirect! after the successful post, then assert the resulting page shows
the correct answer, explanation, and passed/completed state for the quiz; use
the existing quiz, question, and user setup to keep the test focused on the
pass-after-attempt behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/controllers/api/practices/learning_controller.rb`:
- Around line 42-49: The find_or_initialize_learning flow currently assigns
params[:status] directly to learning.status, which can raise when the value is
not a valid enum. Update LearningController#find_or_initialize_learning to
whitelist only the allowed status values (unstarted, started, submitted,
complete) before converting and assigning, and fall back safely when
params[:status] is nil or invalid so the enum setter never receives an
unsupported value.

In `@app/controllers/mentor/practices/practice_quiz/questions_controller.rb`:
- Around line 53-55: `QuestionsController#set_practice_quiz` currently assigns
`@practice.practice_quiz` without handling the nil case, which can lead to
`NoMethodError` in `new`, `create`, and `set_question` when a practice quiz has
not been created. Update this before-action to match
`PracticeQuizController#set_practice_quiz` by checking for a blank
`@practice_quiz` and redirecting appropriately instead of continuing. Make sure
the guard covers all question actions so
`@practice_quiz.practice_quiz_questions` is never called on nil.

In `@test/integration/practice_quizzes_test.rb`:
- Around line 32-40: The test is using practice5, which is a submission-based
practice in this PR, so it is asserting the wrong completion contract. Update
the integration test around api_practice_learning_path and Learning.find_by! to
use a non-submission practice for the “complete without quiz” case, or
explicitly create an approved submission/Product before calling the complete
action. Keep the test aligned with the actual behavior of practices that require
submissions.

---

Nitpick comments:
In `@db/migrate/20260627120618_create_practice_quiz_attempts.rb`:
- Around line 3-10: The practice_quiz_attempts table only has single-column
indexes from the references, but the cooldown and passed-check queries will
repeatedly filter by practice_quiz_id and user_id and sort or look up by
submitted_at. Add a composite index on practice_quiz_attempts using the
create_table block in the migration so the schema supports those access patterns
efficiently; use the existing practice_quiz_attempts table definition as the
place to introduce the new index alongside the references.

In `@test/integration/practice_quizzes_test.rb`:
- Around line 43-65: The retry-lock test for PracticeQuiz attempts only checks
that the second submission is rejected, but it does not cover the expected user
guidance showing when the quiz can be taken again. Update the test around
practice_practice_quiz_attempts_path and practice_practice_quiz_path to assert
that the redirect response includes the next available attempt time in either
the flash message or rendered content, alongside the existing no-new-attempt
check.
- Around line 6-30: The practice quiz flow currently only asserts the redirect
after a passing attempt, so it can miss regressions in the post-pass UI. Update
the integration test in practice_quizzes_test around
practice_practice_quiz_attempts_path to follow_redirect! after the successful
post, then assert the resulting page shows the correct answer, explanation, and
passed/completed state for the quiz; use the existing quiz, question, and user
setup to keep the test focused on the pass-after-attempt behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dfcb932b-cd25-4e75-a017-22b69e88968c

📥 Commits

Reviewing files that changed from the base of the PR and between 525a582 and 501aaa2.

📒 Files selected for processing (41)
  • app/controllers/api/practices/learning_controller.rb
  • app/controllers/mentor/practices/practice_quiz/questions_controller.rb
  • app/controllers/mentor/practices/practice_quiz_controller.rb
  • app/controllers/practices/practice_quiz/attempts_controller.rb
  • app/controllers/practices/practice_quiz_controller.rb
  • app/helpers/page_tabs/practices_helper.rb
  • app/models/learning_status_updater.rb
  • app/models/practice.rb
  • app/models/practice_quiz.rb
  • app/models/practice_quiz_answer.rb
  • app/models/practice_quiz_attempt.rb
  • app/models/practice_quiz_choice.rb
  • app/models/practice_quiz_question.rb
  • app/views/mentor/practices/_mentor_practices.html.slim
  • app/views/mentor/practices/practice_quiz/_form.html.slim
  • app/views/mentor/practices/practice_quiz/edit.html.slim
  • app/views/mentor/practices/practice_quiz/new.html.slim
  • app/views/mentor/practices/practice_quiz/questions/_form.html.slim
  • app/views/mentor/practices/practice_quiz/questions/edit.html.slim
  • app/views/mentor/practices/practice_quiz/questions/new.html.slim
  • app/views/practices/practice_quiz/show.html.slim
  • app/views/practices/show.html.slim
  • config/routes.rb
  • config/routes/mentor.rb
  • db/migrate/20260627120612_create_practice_quizzes.rb
  • db/migrate/20260627120614_create_practice_quiz_questions.rb
  • db/migrate/20260627120616_create_practice_quiz_choices.rb
  • db/migrate/20260627120618_create_practice_quiz_attempts.rb
  • db/migrate/20260627120621_create_practice_quiz_answers.rb
  • db/schema.rb
  • test/fixtures/practice_quiz_answers.yml
  • test/fixtures/practice_quiz_attempts.yml
  • test/fixtures/practice_quiz_choices.yml
  • test/fixtures/practice_quiz_questions.yml
  • test/fixtures/practice_quizzes.yml
  • test/integration/mentor/practice_quizzes_test.rb
  • test/integration/practice_quizzes_test.rb
  • test/models/learning_status_updater_test.rb
  • test/models/practice_quiz_attempt_test.rb
  • test/models/practice_quiz_question_test.rb
  • test/models/practice_quiz_test.rb

Comment thread app/controllers/api/practices/learning_controller.rb
Comment thread test/integration/practice_quizzes_test.rb Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Caution

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

⚠️ Outside diff range comments (1)
db/schema.rb (1)

589-599: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

practice_quiz_answers が設問と選択肢の対応関係をDBで保証していません。

今の定義だと、別設問に属する practice_quiz_choice_id と任意の practice_quiz_question_id を同じ回答行に保存できてしまいます。これでは採点結果や正解表示の元データが壊れるので、組み合わせを複合制約で縛るか、practice_quiz_question_id を冗長保持しない形に寄せたほうが安全です。

Also applies to: 1223-1225

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@db/schema.rb` around lines 589 - 599, `practice_quiz_answers` の定義では
`practice_quiz_choice_id` と `practice_quiz_question_id`
の整合性がDBで保証されていないため、`practice_quiz_answer`
の保存時に別設問の選択肢を紐づけられてしまう点を修正してください。`PracticeQuizAnswer`
の関連とスキーマを見直し、`practice_quiz_choices` と `practice_quiz_questions`
の対応が複合制約で検証されるようにするか、`practice_quiz_question_id` を冗長に持たず
`practice_quiz_choice_id` から参照する形へ寄せてください。関連箇所は `practice_quiz_answers`
のテーブル定義と、回答作成処理を行う `PracticeQuizAnswer` 周辺です。
🧹 Nitpick comments (2)
test/integration/practice_quizzes_test.rb (2)

96-109: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

multiple_choice の通しテストも1本ほしいです。

今回の機能範囲には単一選択と複数選択の両方が含まれていますが、このヘルパー経由のテストは single_choice しか通していません。複数正解の送信・採点・合格判定を1ケース追加しないと、片系統だけ通ってもう一方が壊れていても検知できません。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/practice_quizzes_test.rb` around lines 96 - 109, The
integration helper create_quiz currently only builds a single_choice quiz, so
add a separate multiple_choice end-to-end test that uses the same PracticeQuiz
and practice_quiz_questions flow but creates a multiple_choice question with
more than one correct practice_quiz_choice. Verify the full submit-and-score
path in practice/integration coverage, including answering multiple correct
options and checking the pass/fail outcome, so both branches of the quiz logic
are exercised.

59-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

失敗時に正答・解説を見せない契約もここで固定したいです。

このケースはリトライ抑止と待機文言だけを見ていて、PR要件の「失敗時は正解・解説を表示しない」を担保できていません。follow_redirect! 後に '正解''解説です。' を含まないことも確認しておくと、この分岐の回帰を防げます。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/practice_quizzes_test.rb` around lines 59 - 83, Update the
integration test for the retry-blocking flow in practice_quizzes_test by
extending the existing post-failure assertions after follow_redirect! so it also
verifies the response does not expose the correct answer or explanation. Use the
existing practice_practice_quiz_attempts_path, practice_practice_quiz_path, and
create_quiz flow as the anchor, and add negative checks for the failure page
content such as the answer/explanation text to lock in the “no 正解・解説 on failure”
contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@db/schema.rb`:
- Around line 589-599: `practice_quiz_answers` の定義では `practice_quiz_choice_id` と
`practice_quiz_question_id` の整合性がDBで保証されていないため、`practice_quiz_answer`
の保存時に別設問の選択肢を紐づけられてしまう点を修正してください。`PracticeQuizAnswer`
の関連とスキーマを見直し、`practice_quiz_choices` と `practice_quiz_questions`
の対応が複合制約で検証されるようにするか、`practice_quiz_question_id` を冗長に持たず
`practice_quiz_choice_id` から参照する形へ寄せてください。関連箇所は `practice_quiz_answers`
のテーブル定義と、回答作成処理を行う `PracticeQuizAnswer` 周辺です。

---

Nitpick comments:
In `@test/integration/practice_quizzes_test.rb`:
- Around line 96-109: The integration helper create_quiz currently only builds a
single_choice quiz, so add a separate multiple_choice end-to-end test that uses
the same PracticeQuiz and practice_quiz_questions flow but creates a
multiple_choice question with more than one correct practice_quiz_choice. Verify
the full submit-and-score path in practice/integration coverage, including
answering multiple correct options and checking the pass/fail outcome, so both
branches of the quiz logic are exercised.
- Around line 59-83: Update the integration test for the retry-blocking flow in
practice_quizzes_test by extending the existing post-failure assertions after
follow_redirect! so it also verifies the response does not expose the correct
answer or explanation. Use the existing practice_practice_quiz_attempts_path,
practice_practice_quiz_path, and create_quiz flow as the anchor, and add
negative checks for the failure page content such as the answer/explanation text
to lock in the “no 正解・解説 on failure” contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 873c0abe-54ff-4750-b653-88acd3efb93e

📥 Commits

Reviewing files that changed from the base of the PR and between 501aaa2 and 6a5986c.

📒 Files selected for processing (5)
  • app/controllers/api/practices/learning_controller.rb
  • app/controllers/mentor/practices/practice_quiz/questions_controller.rb
  • db/migrate/20260627120618_create_practice_quiz_attempts.rb
  • db/schema.rb
  • test/integration/practice_quizzes_test.rb
🚧 Files skipped from review as they are similar to previous changes (3)
  • db/migrate/20260627120618_create_practice_quiz_attempts.rb
  • app/controllers/mentor/practices/practice_quiz/questions_controller.rb
  • app/controllers/api/practices/learning_controller.rb

@komagata

Copy link
Copy Markdown
Member Author

@coderabbitai

追加指摘に対応しました。

  • practice_quiz_answers から冗長な practice_quiz_question_id を削除し、回答は practice_quiz_choice_id 経由で設問に紐づく形にしました。
  • 複数選択式の通しテストを追加しました。
  • 不合格後のクールダウン表示で正答・解説が表示されないことをテストに追加しました。

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@komagata 対応ありがとうございます。
冗長な関連の整理に加えて、複数選択の通しテストと、不合格後のクールダウン中に正答・解説が出ないことまでカバーされたのを確認しました。良い修正だと思います。

ᕱ⑅ᕱ


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/integration/practice_quizzes_test.rb`:
- Around line 82-84: The `create_quiz` response assertion is using the generic
string `正解`, which can match the `不正解` label and cause false failures. Update
the check in `practice_quizzes_test` to assert against a non-overlapping, unique
phrase from the success/explanation text instead, or replace it with a more
specific absence assertion tied to the actual rendered content so the test only
fails when the correct answer text is truly present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3b79c70-b8bd-484e-be4c-589e5accca3a

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5986c and be26460.

📒 Files selected for processing (14)
  • app/assets/stylesheets/application.css
  • app/assets/stylesheets/application/blocks/practice-quiz/_practice-quiz.css
  • app/models/practice_quiz_answer.rb
  • app/models/practice_quiz_attempt.rb
  • app/views/mentor/practices/practice_quiz/_form.html.slim
  • app/views/mentor/practices/practice_quiz/edit.html.slim
  • app/views/mentor/practices/practice_quiz/new.html.slim
  • app/views/mentor/practices/practice_quiz/questions/_form.html.slim
  • app/views/mentor/practices/practice_quiz/questions/edit.html.slim
  • app/views/mentor/practices/practice_quiz/questions/new.html.slim
  • app/views/practices/practice_quiz/show.html.slim
  • db/migrate/20260627120621_create_practice_quiz_answers.rb
  • db/schema.rb
  • test/integration/practice_quizzes_test.rb
💤 Files with no reviewable changes (3)
  • db/migrate/20260627120621_create_practice_quiz_answers.rb
  • app/models/practice_quiz_answer.rb
  • db/schema.rb
✅ Files skipped from review due to trivial changes (1)
  • app/assets/stylesheets/application.css
🚧 Files skipped from review as they are similar to previous changes (7)
  • app/views/mentor/practices/practice_quiz/questions/edit.html.slim
  • app/views/mentor/practices/practice_quiz/_form.html.slim
  • app/views/mentor/practices/practice_quiz/questions/_form.html.slim
  • app/views/mentor/practices/practice_quiz/edit.html.slim
  • app/views/mentor/practices/practice_quiz/questions/new.html.slim
  • app/views/practices/practice_quiz/show.html.slim
  • app/models/practice_quiz_attempt.rb

Comment thread test/integration/practice_quizzes_test.rb

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/models/practice_quiz_choice.rb`:
- Line 5: The `practice_quiz_choice` association is currently destroying related
`practice_quiz_answers`, which can erase historical answer data when choices are
replaced. Update `has_many :practice_quiz_answers` to avoid cascading deletes
from `PracticeQuizChoice`—prefer restricting deletion or otherwise preserving
`practice_quiz_answers` so `practice_quiz_attempts` remain consistent. Keep the
fix localized to the `PracticeQuizChoice` model association.

In `@db/fixtures/practice_quiz_attempts.yml`:
- Around line 4-10: The practice quiz attempt fixtures use relative timestamps
in the `submitted_at` field, which makes cooldown and next-available-time
behavior depend on fixture load time. Update the `practice_quiz_attempts.yml`
fixture entries to use fixed, deterministic datetimes instead of `2.hours.ago`
and `20.minutes.ago`, or otherwise ensure the time source is fixed in the code
that reads these records.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 516111cd-4b32-40fb-ac44-03bea3a249a6

📥 Commits

Reviewing files that changed from the base of the PR and between be26460 and ff98892.

📒 Files selected for processing (8)
  • app/models/practice_quiz_choice.rb
  • app/models/practice_quiz_question.rb
  • db/fixtures/practice_quiz_answers.yml
  • db/fixtures/practice_quiz_attempts.yml
  • db/fixtures/practice_quiz_choices.yml
  • db/fixtures/practice_quiz_questions.yml
  • db/fixtures/practice_quizzes.yml
  • db/seeds.rb
✅ Files skipped from review due to trivial changes (1)
  • db/fixtures/practice_quiz_answers.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/models/practice_quiz_question.rb

Comment thread app/models/practice_quiz_choice.rb Outdated
Comment thread db/fixtures/practice_quiz_attempts.yml Outdated
komagata and others added 7 commits July 1, 2026 14:54
- 学生向けshowを状態別バナー+問題カード+block-checks選択肢に刷新し、
  合格後は正解ハイライト・正解バッジ・解説ボックスを表示
- メンターの作成/編集/問題フォームを模範解答ページと同じ
  プラクティス文脈のヘッダー+タブ構成に統一し、カード・バッジ・
  トグル式チェックでサーベイ機能と表現を揃える
- クイズ専用スタイルを practice-quiz ブロックとして追加

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@komagata komagata force-pushed the codex/practice-quizzes branch from de26891 to f831eb8 Compare July 1, 2026 05:55

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
db/schema.rb (1)

589-597: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

practice_quiz_answersに一意制約の追加を検討してください。

practice_quiz_attempt_idpractice_quiz_choice_idの組み合わせに対するユニークインデックスがありません。二重送信や再送信バグにより同一の選択肢に対する回答が重複して保存される可能性があり、正答判定ロジックに影響しうるデータ整合性上のリスクとなります。

💡 提案(マイグレーション例)
add_index :practice_quiz_answers, [:practice_quiz_attempt_id, :practice_quiz_choice_id], unique: true, name: 'index_practice_quiz_answers_uniqueness'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@db/schema.rb` around lines 589 - 597, `practice_quiz_answers`
のデータ整合性を守るため、`practice_quiz_attempt_id` と `practice_quiz_choice_id`
の組み合わせに一意制約を追加してください。`practice_quiz_answers` のスキーマ定義を更新し、`practice_quiz_answers`
に対する複合ユニークインデックスを追加するマイグレーションを入れてください。既存の `practice_quiz_answers` の
`practice_quiz_attempt_id` / `practice_quiz_choice_id` を参照する箇所も確認し、重複作成を防ぐ
`PracticeQuizAnswer` の保存ロジックと整合するようにしてください。
app/helpers/page_tabs/practices_helper.rb (1)

22-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

LGTM(命名は軽微な懸念あり)

edit/new分岐によるパス決定ロジックは単純で正しいです。ただしmentor_practice_quiz_pathという命名は、実在するRailsルートヘルパーのように見えるため、実際にはローカルヘルパーであることが分かりにくい点は任意で改善余地があります(例: mentor_practice_quiz_management_path)。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/helpers/page_tabs/practices_helper.rb` around lines 22 - 28, The logic in
mentor_practice_quiz_path is fine, but the name can be misleading because it
looks like a generated Rails route helper rather than a local helper method.
Consider renaming the helper to something more explicit, such as a management-
or wrapper-style name, and update any callers so it is clear this method chooses
between edit_mentor_practice_practice_quiz_path and
new_mentor_practice_practice_quiz_path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/helpers/page_tabs/practices_helper.rb`:
- Line 17: The tab builder in page_tabs/practices_helper.rb is calling
current_user.admin_or_mentor? without handling guests, which can raise
NoMethodError on the public practice show page. Update the condition in the
helper method that adds the “理解度テスト管理” tab to safely handle a nil current_user,
using safe navigation or an equivalent nil check before calling
admin_or_mentor?. Keep the change localized to the tab generation logic so
authenticated users still see the tab and guests do not.

---

Nitpick comments:
In `@app/helpers/page_tabs/practices_helper.rb`:
- Around line 22-28: The logic in mentor_practice_quiz_path is fine, but the
name can be misleading because it looks like a generated Rails route helper
rather than a local helper method. Consider renaming the helper to something
more explicit, such as a management- or wrapper-style name, and update any
callers so it is clear this method chooses between
edit_mentor_practice_practice_quiz_path and
new_mentor_practice_practice_quiz_path.

In `@db/schema.rb`:
- Around line 589-597: `practice_quiz_answers`
のデータ整合性を守るため、`practice_quiz_attempt_id` と `practice_quiz_choice_id`
の組み合わせに一意制約を追加してください。`practice_quiz_answers` のスキーマ定義を更新し、`practice_quiz_answers`
に対する複合ユニークインデックスを追加するマイグレーションを入れてください。既存の `practice_quiz_answers` の
`practice_quiz_attempt_id` / `practice_quiz_choice_id` を参照する箇所も確認し、重複作成を防ぐ
`PracticeQuizAnswer` の保存ロジックと整合するようにしてください。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e334c60c-8207-4142-926b-72e6b8c2141f

📥 Commits

Reviewing files that changed from the base of the PR and between ff98892 and f831eb8.

📒 Files selected for processing (50)
  • app/assets/stylesheets/application.css
  • app/assets/stylesheets/application/blocks/practice-quiz/_practice-quiz.css
  • app/controllers/api/practices/learning_controller.rb
  • app/controllers/mentor/practices/practice_quiz/questions_controller.rb
  • app/controllers/mentor/practices/practice_quiz_controller.rb
  • app/controllers/practices/practice_quiz/attempts_controller.rb
  • app/controllers/practices/practice_quiz_controller.rb
  • app/helpers/page_tabs/practices_helper.rb
  • app/models/learning_status_updater.rb
  • app/models/practice.rb
  • app/models/practice_quiz.rb
  • app/models/practice_quiz_answer.rb
  • app/models/practice_quiz_attempt.rb
  • app/models/practice_quiz_choice.rb
  • app/models/practice_quiz_question.rb
  • app/views/mentor/practices/_mentor_practices.html.slim
  • app/views/mentor/practices/practice_quiz/_form.html.slim
  • app/views/mentor/practices/practice_quiz/edit.html.slim
  • app/views/mentor/practices/practice_quiz/new.html.slim
  • app/views/mentor/practices/practice_quiz/questions/_form.html.slim
  • app/views/mentor/practices/practice_quiz/questions/edit.html.slim
  • app/views/mentor/practices/practice_quiz/questions/new.html.slim
  • app/views/practices/practice_quiz/show.html.slim
  • app/views/practices/show.html.slim
  • config/routes.rb
  • config/routes/mentor.rb
  • db/fixtures/practice_quiz_answers.yml
  • db/fixtures/practice_quiz_attempts.yml
  • db/fixtures/practice_quiz_choices.yml
  • db/fixtures/practice_quiz_questions.yml
  • db/fixtures/practice_quizzes.yml
  • db/fixtures/practices.yml
  • db/migrate/20260627120612_create_practice_quizzes.rb
  • db/migrate/20260627120614_create_practice_quiz_questions.rb
  • db/migrate/20260627120616_create_practice_quiz_choices.rb
  • db/migrate/20260627120618_create_practice_quiz_attempts.rb
  • db/migrate/20260627120621_create_practice_quiz_answers.rb
  • db/schema.rb
  • db/seeds.rb
  • test/fixtures/practice_quiz_answers.yml
  • test/fixtures/practice_quiz_attempts.yml
  • test/fixtures/practice_quiz_choices.yml
  • test/fixtures/practice_quiz_questions.yml
  • test/fixtures/practice_quizzes.yml
  • test/integration/mentor/practice_quizzes_test.rb
  • test/integration/practice_quizzes_test.rb
  • test/models/learning_status_updater_test.rb
  • test/models/practice_quiz_attempt_test.rb
  • test/models/practice_quiz_question_test.rb
  • test/models/practice_quiz_test.rb
✅ Files skipped from review due to trivial changes (9)
  • test/fixtures/practice_quiz_answers.yml
  • test/fixtures/practice_quizzes.yml
  • db/fixtures/practice_quiz_answers.yml
  • test/fixtures/practice_quiz_attempts.yml
  • test/fixtures/practice_quiz_questions.yml
  • db/fixtures/practice_quizzes.yml
  • test/fixtures/practice_quiz_choices.yml
  • db/fixtures/practice_quiz_choices.yml
  • db/fixtures/practices.yml
🚧 Files skipped from review as they are similar to previous changes (38)
  • app/assets/stylesheets/application.css
  • config/routes.rb
  • test/models/learning_status_updater_test.rb
  • app/controllers/practices/practice_quiz_controller.rb
  • db/migrate/20260627120621_create_practice_quiz_answers.rb
  • db/migrate/20260627120616_create_practice_quiz_choices.rb
  • app/models/learning_status_updater.rb
  • db/fixtures/practice_quiz_attempts.yml
  • db/fixtures/practice_quiz_questions.yml
  • db/seeds.rb
  • app/views/mentor/practices/practice_quiz/questions/new.html.slim
  • db/migrate/20260627120614_create_practice_quiz_questions.rb
  • app/views/mentor/practices/practice_quiz/questions/edit.html.slim
  • app/views/mentor/practices/practice_quiz/new.html.slim
  • test/models/practice_quiz_attempt_test.rb
  • app/assets/stylesheets/application/blocks/practice-quiz/_practice-quiz.css
  • app/models/practice_quiz_choice.rb
  • app/models/practice_quiz_attempt.rb
  • app/models/practice_quiz_answer.rb
  • db/migrate/20260627120618_create_practice_quiz_attempts.rb
  • db/migrate/20260627120612_create_practice_quizzes.rb
  • test/models/practice_quiz_question_test.rb
  • config/routes/mentor.rb
  • app/views/mentor/practices/_mentor_practices.html.slim
  • test/models/practice_quiz_test.rb
  • app/views/mentor/practices/practice_quiz/edit.html.slim
  • app/views/practices/show.html.slim
  • app/views/mentor/practices/practice_quiz/_form.html.slim
  • app/views/practices/practice_quiz/show.html.slim
  • app/views/mentor/practices/practice_quiz/questions/_form.html.slim
  • app/models/practice_quiz.rb
  • app/models/practice_quiz_question.rb
  • app/controllers/mentor/practices/practice_quiz_controller.rb
  • app/controllers/practices/practice_quiz/attempts_controller.rb
  • app/controllers/mentor/practices/practice_quiz/questions_controller.rb
  • app/models/practice.rb
  • app/controllers/api/practices/learning_controller.rb
  • test/integration/practice_quizzes_test.rb

Comment thread app/helpers/page_tabs/practices_helper.rb Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 作業中

Development

Successfully merging this pull request may close these issues.

プラクティスに理解度テスト機能を追加する

1 participant