Skip to content

連続学習記録にオンオフ機能を追加#9820

Open
y-kawahara-gs wants to merge 7 commits intomainfrom
feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off
Open

連続学習記録にオンオフ機能を追加#9820
y-kawahara-gs wants to merge 7 commits intomainfrom
feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off

Conversation

@y-kawahara-gs
Copy link
Copy Markdown
Contributor

@y-kawahara-gs y-kawahara-gs commented Mar 23, 2026

Issue

概要

  • ダッシュボート・プロフィール画面に表示される学習連続記録の表示にオンオフ機能を実装しました。

変更確認方法

  1. feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-offをローカルに取り込む
  2. bin/rails db:migrateを行う
  3. kimuraでログインする
  4. 日報作成ページ に遷移し、学習時間を付けて日報を作成する
  5. ダッシュボードの以下のトグルがOFFになっているのを確認し、ONにする
image
  1. ダッシュボードにリダイレクトし、学習連続記録が表示されるのを確認する
image
  1. kimuraのマイページ5、6の動作を試す。

Screenshot

変更前

変更後

Summary by CodeRabbit

リリースノート

  • 新機能

    • 学習連続記録の表示/非表示をトグル切り替えできるようになりました。ユーザーはプロフィール・ダッシュボードから、学習連続記録をいつでも表示または非表示に設定できます。既存の記録は削除されません。
  • テスト

    • 新機能の動作確認テストを追加しました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 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

概要

学習連続記録(study streak)の表示/非表示をユーザーが切り替えられるようにする機能を追加します。新しいデータベースカラム、ビューコンポーネント、コントローラアクション、検証、およびルーティングが含まれます。

変更内容

コホート / ファイル(s) 概要
ビューコンポーネント
app/components/study_streak/toggle_component.rb, app/components/study_streak/toggle_component.html.slim
学習連続記録の表示/非表示を切り替えるコンポーネントを新規追加。フォーム送信時に自動的にチェックボックス変更を検出し、PATCHリクエストを送信する機能を実装。
コントローラとルーティング
app/controllers/users_controller.rb, config/routes/users.rb
新しいアクション toggle_show_study_streak を追加。PATCH リクエストで show_study_streak を更新し、リダイレクト先へ遷移する処理を実装。
モデル検証
app/models/user.rb
show_study_streak 属性に対して真偽値のみを許可する検証を追加。
ビューテンプレート更新
app/views/home/index.html.slim, app/views/users/show.html.slim
学習連続記録セクションで、トグルコンポーネントを条件付きで表示し、トラッカーコンポーネントは show_study_streak が有効な場合のみレンダリングするよう変更。
データベース
db/migrate/20260323020435_add_show_study_streak_to_users.rb, db/schema.rb
users テーブルに show_study_streak カラム(ブール値、デフォルト: false)を追加するマイグレーションとスキーマ定義を追加。
ローカライズと設定
config/locales/ja.yml
日本語翻訳キー show_study_streak を ActiveRecord 属性に追加。
システムテスト
test/system/home_test.rb, test/system/users_test.rb
トグル機能の動作を検証するシステムテストを追加。表示/非表示の切り替え、データ永続化、UI 反映を確認。

🎯 3 (Moderate) | ⏱️ ~20 分

関連する可能性のあるプルリクエスト

推奨レビュアー

  • smallmonkeykey
  • komagata

🐰 トグルをカチッと切り替えれば
連続の記録は隠れけり
ユーザーの選択、尊重して
学習の道も自由自在
データは消えず静かに待つ 📚✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PRのタイトルは「連続学習記録にオンオフ機能を追加」であり、変更セットの主要な目的である学習連続記録のオンオフ機能の実装を明確かつ簡潔に説明しています。
Description check ✅ Passed PR説明はテンプレートの必須セクション(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-function-to-toggle-display-of-continuous-learning-streak-on-or-off

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 changed the title Userモデルにshow_study_streakカラムを追加 連続学習記録にオンオフ機能を追加 Mar 23, 2026
@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off branch 2 times, most recently from 9aebdeb to 84a7dee Compare March 24, 2026 09:32
@machida machida self-assigned this Mar 25, 2026
@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off branch from 84a7dee to a539c55 Compare March 26, 2026 04:33
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

🚀 Review App

URL: https://bootcamp-pr-9820-fvlfu45apq-an.a.run.app

Basic認証: fjord / (ステージングと同じ)
PR更新時に自動で再デプロイされます。

@y-kawahara-gs y-kawahara-gs marked this pull request as ready for review March 26, 2026 05:56
@github-actions github-actions bot requested a review from komagata March 26, 2026 05:56
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/components/study_streak/toggle_component.html.slim`:
- Line 33: In the toggle_component.html.slim template
(study_streak/toggle_component.html.slim) fix the Japanese typo by replacing the
string "ダッシュボート" with the correct "ダッシュボード" so the sentence reads
「学習連続記録はプロフィールとダッシュボードに表示され、他のユーザーからも閲覧されます。」; update only that literal in the
view template to correct the display text.

In `@app/controllers/users_controller.rb`:
- Around line 87-91: 現在の toggle_show_study_streak アクションは
current_user.toggle_show_study_streak! による反転更新で、再送や二重送信で状態がずれるため冪等ではありません。params
で明示的な状態(例: params[:show_study_streak] が "true"/"false")を受け取り、toggle ではなく
current_user.update!(show_study_streak: parsed_value)
のように明示的に更新するロジックに変更してください(パラメータのパース/バリデーションを行い、必要なら nil
の場合は既存の動作を維持)。redirect_to の部分(url_from(params[:redirect_to]) ||
root_path)はそのまま保持してください。
🪄 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: a5b978de-5066-4286-bbfc-e6200b56491c

📥 Commits

Reviewing files that changed from the base of the PR and between ad44c68 and a539c55.

⛔ Files ignored due to path filters (1)
  • app/assets/images/study_streak/about-study-streak.jpg is excluded by !**/*.jpg
📒 Files selected for processing (10)
  • app/components/study_streak/toggle_component.html.slim
  • app/components/study_streak/toggle_component.rb
  • app/controllers/users_controller.rb
  • app/models/user.rb
  • app/views/home/index.html.slim
  • app/views/users/show.html.slim
  • config/locales/ja.yml
  • config/routes/users.rb
  • db/migrate/20260323020435_add_show_study_streak_to_users.rb
  • db/schema.rb

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off branch 5 times, most recently from 91459b4 to 29067e4 Compare March 26, 2026 10:33
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 (2)
test/system/users_test.rb (1)

73-74: 2回目のトグル後のアサーションが不足しています。

Line 73 で2回目のクリックを行っていますが、その後の状態を検証していません。トグルが元の状態に戻ることを確認するアサーションを追加することを推奨します。

♻️ 修正案
   assert find('#toggle', visible: false).checked?
   find('label.a-on-off-checkbox').click
+
+  assert_equal before, user.reload.show_study_streak
+  assert_no_selector 'div.a-card.streak-card'
+  assert_not find('#toggle', visible: false).checked?
 end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/system/users_test.rb` around lines 73 - 74, The test in
test/system/users_test.rb clicks the toggle twice using
find('label.a-on-off-checkbox').click but lacks an assertion after the second
click; add an assertion after the second click that verifies the toggle returned
to its original state (for example by asserting the checkbox/input associated
with 'label.a-on-off-checkbox' has the original checked/unchecked value or the
UI shows the original state), placing the assertion immediately after the second
find('label.a-on-off-checkbox').click to validate the toggle behavior.
test/system/home_test.rb (1)

68-69: 2回目のトグル後のアサーションが不足しています。

users_test.rb と同様に、2回目のクリック後の状態検証がありません。

♻️ 修正案
   assert find('#toggle', visible: false).checked?
   find('label.a-on-off-checkbox').click
+
+  assert_equal before, user.reload.show_study_streak
+  assert_no_selector 'div.a-card.streak-card'
+  assert_not find('#toggle', visible: false).checked?
 end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/system/home_test.rb` around lines 68 - 69, home_test.rb is missing an
assertion after the second toggle click; replicate the pattern used in
users_test.rb by performing the second click on the same element
(find('label.a-on-off-checkbox').click) and then asserting the expected
post-toggle state (e.g., checkbox checked/unchecked or related DOM text/state)
using the same helper/assertion used in users_test.rb so the test verifies both
toggle transitions.
🤖 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/system/home_test.rb`:
- Around line 68-69: home_test.rb is missing an assertion after the second
toggle click; replicate the pattern used in users_test.rb by performing the
second click on the same element (find('label.a-on-off-checkbox').click) and
then asserting the expected post-toggle state (e.g., checkbox checked/unchecked
or related DOM text/state) using the same helper/assertion used in users_test.rb
so the test verifies both toggle transitions.

In `@test/system/users_test.rb`:
- Around line 73-74: The test in test/system/users_test.rb clicks the toggle
twice using find('label.a-on-off-checkbox').click but lacks an assertion after
the second click; add an assertion after the second click that verifies the
toggle returned to its original state (for example by asserting the
checkbox/input associated with 'label.a-on-off-checkbox' has the original
checked/unchecked value or the UI shows the original state), placing the
assertion immediately after the second find('label.a-on-off-checkbox').click to
validate the toggle behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20d7be23-4cba-40d3-ae4c-64a939e1a038

📥 Commits

Reviewing files that changed from the base of the PR and between 7e3d4fc and 29067e4.

⛔ Files ignored due to path filters (1)
  • app/assets/images/study_streak/about-study-streak.jpg is excluded by !**/*.jpg
📒 Files selected for processing (12)
  • app/components/study_streak/toggle_component.html.slim
  • app/components/study_streak/toggle_component.rb
  • app/controllers/users_controller.rb
  • app/models/user.rb
  • app/views/home/index.html.slim
  • app/views/users/show.html.slim
  • config/locales/ja.yml
  • config/routes/users.rb
  • db/migrate/20260323020435_add_show_study_streak_to_users.rb
  • db/schema.rb
  • test/system/home_test.rb
  • test/system/users_test.rb
✅ Files skipped from review due to trivial changes (5)
  • config/locales/ja.yml
  • config/routes/users.rb
  • app/components/study_streak/toggle_component.rb
  • db/migrate/20260323020435_add_show_study_streak_to_users.rb
  • app/components/study_streak/toggle_component.html.slim
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/models/user.rb
  • app/views/home/index.html.slim
  • db/schema.rb

@machida
Copy link
Copy Markdown
Member

machida commented Mar 26, 2026

@y-kawahara-gs

デザイン入れましたー

変更の概要

  • StudyStreakTrackerComponent にトグルとモーダルを組み込み、ToggleComponent
    を別カードとして表示するのをやめた
  • 学習連続記録がONのときはカードヘッダーにトグルと「学習連続記録とは?」を表示
  • 学習連続記録がOFFのときもカードヘッダーのみ表示しトグルでONに戻せる
  • attr_reader :target_user を private 以下に移動

@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off branch 2 times, most recently from 02f54ad to a0af7a6 Compare March 26, 2026 12:56
@y-kawahara-gs y-kawahara-gs force-pushed the feature/add-function-to-toggle-display-of-continuous-learning-streak-on-or-off branch from a0af7a6 to 1d57c72 Compare March 27, 2026 00:12
@y-kawahara-gs
Copy link
Copy Markdown
Contributor Author

@Miya096jp
お疲れ様です!
こちらのPRのメンバーレビューを依頼したいのですが、
ご都合いかがでしょうか?🙏

@s-tone-gs
Copy link
Copy Markdown
Contributor

@y-kawahara-gs
横から失礼します~
Miyaさん現在ご都合悪そうなので別の方に依頼した方がいいかな~と思います。
ref: #9796 (comment)

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

@djkazunoko
お疲れ様です!
メンバーレビューを依頼したいのですが、
ご都合いかがでしょうか?

@djkazunoko
Copy link
Copy Markdown
Contributor

@y-kawahara-gs
お疲れ様です!
来週中に対応いたします!

@djkazunoko djkazunoko self-requested a review April 1, 2026 01:43
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.

4 participants