Skip to content

検索機能を拡充:自分のみのチェックボックスを追加#8277

Merged
komagata merged 16 commits intomainfrom
feature/searchable-filtering-login-user
Jul 23, 2025
Merged

検索機能を拡充:自分のみのチェックボックスを追加#8277
komagata merged 16 commits intomainfrom
feature/searchable-filtering-login-user

Conversation

@kitarou888
Copy link
Copy Markdown
Contributor

@kitarou888 kitarou888 commented Jan 15, 2025

Issue

概要

ヘッダーにある検索フォームに「自分のみ」のチェックボックスを追加し、自分が書いた日報その他のみをフィルタリングできるようにした。

変更確認方法

  1. 本PRのブランチをローカルに取り込むfeature/searchable-filtering-login-userをローカルに取り込む
    1. git fetch origin pull/8277/head:pr-8277-review
    2. git switch pr-8277-review
  2. ローカルでアプリを起動
    1. bin/setup
    2. foreman start -f Procfile.dev
  3. 任意のユーザーでログイン(例.ユーザー名machida、パスワードtesttest
  4. ヘッダー右上にある「検索」ボタンをクリック→検索モーダルが開く
image image
  1. 検索モーダル上で、カテゴリ「お知らせ」、絞り込み条件「自分の投稿のみに絞る」にチェック、として検索ボタンをクリック
image
  1. 自分の投稿(お知らせ)のみが表示されることを確認
image
  1. 再度4を行い、検索ワード「現役生」として検索ボタンをクリック
image
  1. 自分の投稿かつ検索ワードが含まれるお知らせのみ表示されることを確認
image

Screenshot

image

変更前

image

変更後

image

Summary by CodeRabbit

  • 新機能

    • 検索フォームに「自分の投稿のみに絞る」チェックボックスを追加し、自分の投稿だけを検索できるようになりました。
  • 改善

    • 検索フォームのデザインとレイアウトを刷新し、使いやすさと視認性を向上しました。
    • 検索UIの表示・非表示の挙動を見直し、モーダルでの検索体験を統一しました。
  • バグ修正

    • 検索ページのタイトルに「自分の投稿のみ」条件を反映するようにしました。
  • テスト

    • 新しい検索条件(自分の投稿のみ)に対応したテストを追加・更新しました。

@machida
Copy link
Copy Markdown
Member

machida commented Feb 3, 2025

@kitarou888

お待たせしました🙇‍♂️
検索のUIをPCのときもモーダルに変更しました。

image image

これでお願いしますー

@kitarou888 kitarou888 self-assigned this Feb 12, 2025
@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 359ec49 to 0c5c13b Compare February 14, 2025 13:32
@kitarou888
Copy link
Copy Markdown
Contributor Author

kitarou888 commented Feb 15, 2025

@machida
検索結果ページのタイトル表示について、私の方で案を考えてみましたので、ご意見を伺えたらと思います🙏

■ これまで

(検索ワードあり)
image

(検索ワードなし)
image

■ 改善案

(検索ワードあり、自分の投稿のみにチェックあり)
image

(検索ワードあり、自分の投稿のみにチェックなし)
image

(検索ワードなし、自分の投稿のみにチェックあり)
image

(検索ワードなし、自分の投稿のみにチェックなし)
image

@machida
Copy link
Copy Markdown
Member

machida commented Feb 15, 2025

@kitarou888 一旦それでリリースにしようと思います!別PRで人やカテゴリーを線で囲って他の文字と区別するなどの見た目のデザインをしたいと思いますー

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 6bf055f to 68a17e1 Compare July 2, 2025 14:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 2, 2025

Walkthrough

検索機能に「自分の投稿のみ」フィルタを追加し、関連するUI・テスト・スタイルを調整しました。検索フォームとモーダルの見た目・構造が刷新され、検索処理のメソッドシグネチャやテストも新仕様に対応しています。一部不要なスタイルも削除されました。

Changes

ファイル群 変更概要
app/models/searcher.rb, app/controllers/searchables_controller.rb 検索メソッドにonly_me引数追加、呼び出しをキーワード引数化、フィルタ処理追加
app/views/application/header/_header_search.html.slim 検索フォーム構造・ラベル・クラス刷新、「自分の投稿のみ」チェックボックス追加
app/views/application/header/_header_links.html.slim 検索UIの表示・非表示クラスを変更し、モーダルの表示範囲を調整
app/views/searchables/index.html.slim タイトルに「自分の投稿のみ」条件を動的に追加
app/javascript/stylesheets/application.sass header-searchモジュールのimport削除
app/javascript/stylesheets/application/blocks/header/_header-search.sass ヘッダー検索用スタイルシートを全削除
app/javascript/stylesheets/atoms/_a-text-input.sass .a-xs-text-inputクラス定義を削除
test/models/searcher_test.rb, test/models/user_test.rb, test/helpers/search_helper_test.rb 検索メソッド呼び出しをキーワード引数化、「自分の投稿のみ」テスト追加
test/system/searchables_test.rb 検索フォーム操作をモーダル対応に修正
test/system/admin/users/password_test.rb, test/system/current_user/password_test.rb メニュークリック対象を「Me」テキスト指定で絞り込み

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant HeaderView
  participant Modal
  participant SearchablesController
  participant Searcher

  User->>HeaderView: 検索ボタンをクリック
  HeaderView->>Modal: 検索モーダルを表示
  User->>Modal: 検索条件入力・「自分の投稿のみ」チェック
  Modal->>SearchablesController: 検索リクエスト送信 (word, only_me, ...)
  SearchablesController->>Searcher: search(word:, only_me:, current_user:, ...)
  Searcher->>Searcher: only_me条件で検索結果をフィルタ
  Searcher-->>SearchablesController: 検索結果返却
  SearchablesController-->>Modal: 結果を表示
  Modal-->>User: 検索結果閲覧
Loading

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/helpers/search_helper_test.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

'


📜 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 31f2eaf and ab30487.

📒 Files selected for processing (1)
  • test/helpers/search_helper_test.rb (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rb

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

test/**/*

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧠 Learnings (2)
📓 Common learnings
Learnt from: kitarou888
PR: fjordllc/bootcamp#8277
File: test/models/searcher_test.rb:326-331
Timestamp: 2025-07-10T12:59:27.807Z
Learning: モデルテストにおいて、1つのクラスメソッドの複数の挙動を検証する場合、機能の異なる側面を同じテストメソッドでテストすることは、包括的なテストとして適切である。特に`only_me`のような機能では、異なる検索条件(空文字と具体的な検索語)を使い分けることで、より広範囲な動作保証が可能となる。
test/helpers/search_helper_test.rb (1)
Learnt from: kitarou888
PR: fjordllc/bootcamp#8277
File: test/models/searcher_test.rb:326-331
Timestamp: 2025-07-10T12:59:27.807Z
Learning: モデルテストにおいて、1つのクラスメソッドの複数の挙動を検証する場合、機能の異なる側面を同じテストメソッドでテストすることは、包括的なテストとして適切である。特に`only_me`のような機能では、異なる検索条件(空文字と具体的な検索語)を使い分けることで、より広範囲な動作保証が可能となる。
⏰ 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
🔇 Additional comments (1)
test/helpers/search_helper_test.rb (1)

37-37: 新しいAPIシグネチャに正しく対応した更新です。

Searcher.searchメソッドのシグネチャ変更に合わせて、検索語を位置引数からword:キーワード引数に変更している点が適切です。テストの機能性を維持しながら新しいAPIに対応できています。

✨ 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.

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 68a17e1 to 824e06a Compare July 2, 2025 14:57
@kitarou888
Copy link
Copy Markdown
Contributor Author

kitarou888 commented Jul 3, 2025

@machida
で相談しました「検索結果ページタイトル」の仕様ですが、本イシューでは以下の画像のように「自分の投稿のみ」の文言のみ追加するのでもよいでしょうか??

image

理由

  1. 昨日の開発MTGで要望いただいたとおり、町田さんに実装いただいた検索モーダルを早めにマージし、駒形さんが開発中の新しい検索機能実装の際にモーダルを使えるようにすべきであること
  2. 検索結果ページタイトルの実装が現状のReact仕様だと以下のとおり労力に見合わない
    1. タイトル文字をAPIコントローラから受け取るためだけにReactコンポーネントを新規で実装しなければならない割に、nakamu-kazu222さんのイシュー で非React化がもうじきマージされるとその労力が徒労になる
    2. 一方で、非React化がマージされると、APIでないコントローラになるため、インスタンス変数として非常に簡単にタイトル文字列をslimテンプレートファイルに渡せるようになる
    3. 現時点でも以下のようにslimテンプレートにロジックをベタ書きすることでタイトル文字列を作成できますが、コードが汚いうえ非React化がマージされるとこのコードも ⅱ 同様不要になる
image

@kitarou888 kitarou888 marked this pull request as ready for review July 3, 2025 14:31
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c558731 and 8d586cb.

📒 Files selected for processing (9)
  • app/controllers/api/searchables_controller.rb (1 hunks)
  • app/javascript/stylesheets/application.sass (0 hunks)
  • app/javascript/stylesheets/application/blocks/header/_header-search.sass (0 hunks)
  • app/javascript/stylesheets/atoms/_a-text-input.sass (0 hunks)
  • app/models/searcher.rb (2 hunks)
  • app/views/application/header/_header_links.html.slim (2 hunks)
  • app/views/application/header/_header_search.html.slim (1 hunks)
  • app/views/searchables/index.html.slim (1 hunks)
  • test/models/searcher_test.rb (2 hunks)
💤 Files with no reviewable changes (3)
  • app/javascript/stylesheets/application.sass
  • app/javascript/stylesheets/atoms/_a-text-input.sass
  • app/javascript/stylesheets/application/blocks/header/_header-search.sass
🧰 Additional context used
🧠 Learnings (1)
app/views/searchables/index.html.slim (1)
Learnt from: tyrrell-IH
PR: fjordllc/bootcamp#8807
File: app/views/welcome/job_support.html.slim:391-392
Timestamp: 2025-06-21T22:30:20.116Z
Learning: このプロジェクトにはRailsの組み込みmarkdownヘルパが利用できないため、markdownのHTML変換には自前でヘルパを実装する必要がある。
🧬 Code Graph Analysis (1)
app/controllers/api/searchables_controller.rb (1)
app/models/searcher.rb (1)
  • search (20-36)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (10)
app/models/searcher.rb (1)

20-20: メソッドシグネチャの変更は適切です

位置引数からキーワード引数への変更により、メソッドの使いやすさと可読性が向上しています。デフォルト値の設定も適切です。

app/views/searchables/index.html.slim (1)

1-1: タイトルの条件分岐は適切です

params[:only_me] が存在する場合に「自分の投稿のみ」を追加する実装は分かりやすく、ユーザー体験の向上に寄与します。

app/controllers/api/searchables_controller.rb (1)

7-7: コントローラーの実装は適切です

Searcher.search メソッドの新しいシグネチャに対応した実装で、パラメータの受け渡しも正しく行われています。

test/models/searcher_test.rb (1)

20-20: 既存テストの更新は適切です

すべてのテストが新しいキーワード引数形式に正しく更新されています。

Also applies to: 25-25, 30-30, 35-35, 40-40, 45-45, 50-50, 55-55, 60-60, 65-65, 70-70, 76-76, 80-80, 84-84, 90-90, 94-94, 98-98, 104-104, 108-108, 112-112, 118-118, 122-122, 126-126, 132-132, 136-136, 140-140, 146-146, 150-150, 154-154, 160-160, 164-164, 168-168, 174-174, 179-179, 191-191, 196-196, 201-201

app/views/application/header/_header_links.html.slim (1)

3-3: UIの変更は適切です

検索モーダルの実装とヘッダーリンクの表示調整が適切に行われています。新しい検索機能に対応したUI構造の変更が反映されています。

Also applies to: 8-8, 45-47, 53-53

app/views/application/header/_header_search.html.slim (5)

1-3: フォーム構造の改善が適切に実装されています

form_with ヘルパーを使用した適切なフォーム宣言と、新しいCSSクラス構造により、より意味的で整理されたマークアップになっています。.form__items.form__items-inner のネストされたコンテナ構造は、スタイリングとレスポンシブデザインに適しています。


4-8: カテゴリー選択部分のアクセシビリティが向上しています

適切なラベル付けとセマンティックな .form-item コンテナの使用により、フォームのアクセシビリティが向上しています。Searcher::DOCUMENT_TYPES の使用は適切な関心の分離を示しています。


9-18: メイン機能の「自分の投稿のみ」フィルタチェックボックスが適切に実装されています

新しい絞り込み条件セクションが以下の点で適切に実装されています:

  • only_me パラメータの適切な命名とハンドリング
  • params[:only_me].present? による状態管理
  • アクセシビリティを考慮したセマンティックなHTML構造
  • 適切な日本語ラベル「自分の投稿のみに絞る」
  • 他のフォーム要素と一貫性のあるスタイリング

この実装により、ユーザーは自分の投稿のみを検索結果に表示できるようになります。


19-22: 検索ワード入力部分のUXが向上しています

適切なラベル付けと、より具体的なプレースホルダーテキスト「就職が心配な方へ」の使用により、ユーザーエクスペリエンスが向上しています。全体的なフォーム構造との一貫性も保たれています。


23-29: フォームアクション部分が適切に構造化されています

.form-actions コンテナの使用により、フォームの送信部分が適切に構造化されています。検索アイコンと日本語テキストの組み合わせにより、ユーザーにとって分かりやすいUIになっています。

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 8d586cb to ce2d165 Compare July 3, 2025 14:42
@machida
Copy link
Copy Markdown
Member

machida commented Jul 3, 2025

@kitarou888 これでOKですー
「自分の投稿のみ」にデザインを入れます。
それと同時進行でレビューに進めてください🙏

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch 2 times, most recently from cde7a76 to 109314b Compare July 4, 2025 13:33
@kitarou888 kitarou888 requested a review from masyuko0222 July 4, 2025 14:26
@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
お疲れさまです!
こちらのレビューをお願いできますでしょうか🙏

お忙しそうでしたら遠慮なくご連絡いただければと思います!

@masyuko0222
Copy link
Copy Markdown
Contributor

@kitarou888
承知しました~!一週間くらい見て頂ければです!

@masyuko0222
Copy link
Copy Markdown
Contributor

@kitarou888
動作確認で一点気になったのですが、検索カテゴリーを「すべて」にすると『自分の投稿のみ絞る』が効かないようです。
こちらの仕様決まってますか??🙂

上記の場合でも効くようにするか、カテゴリーが「すべて」の場合は『自分の投稿のみ絞る』のチェックボックスを押せないようにした方がいいのかなーと思いました。

@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
「すべて」でフィルタが効かないのは意図した仕様です。

理由は「プラクティス」と「ユーザー」は自分のもののみでフィルタをかけられないため、一括で効かないように実装しています。

models/searcher.rb

      # only_me=true の場合、user_id カラムを持たない :practices および :users は除外してフィルタリング
      searchables = searchables.select { |searchable| searchable.user_id == current_user.id } if only_me && %i[all practices users].exclude?(document_type)

おっしゃる後者の案で修正しようと思います!

@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
ご指摘の件、前者案(すべての場合でもユーザーIDをもつSearchableに対しては自分のもののみフィルタがかかるようにする)にて修正を行いましたので、よろしくお願いします🙏

@masyuko0222
Copy link
Copy Markdown
Contributor

masyuko0222 commented Jul 5, 2025

@kitarou888
すみません、カテゴリーが「すべて」+「自分の投稿のみに絞る」の場合は、user_id カラムを持たない :practices および :users は除外した上で、自分の投稿全体が検索結果に表れる方が良いんじゃないかなという意味でしたm(__)m

「すべて + 自分の投稿のみに絞る」で検索をする人は、自分が投稿した日報や提出物・コメントはまとめて一覧で見たいけど、ユーザーやプラクティスは見えなくても良いんじゃないかなと思いました🤔

自分の投稿のみに絞る、というフィルタなのでユーザーやプラクティスも出てくるとちょっと違和感かもと初めて触る人は思うかもです。

@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
たしかに言われてみればそのとおりですね!
プラクティスやユーザーは自分のものではそもそもないわけですし。
深く考えていただきありがたいです🙏

修正してまた連絡しますね!

@masyuko0222
Copy link
Copy Markdown
Contributor

@kitarou888
いえ、何度もすみません。
主観なので今後のコードレビューでも、違うと思ったら全然言ってもらって大丈夫です。
よろしくお願いします。

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 5a7f333 to a8c22e0 Compare July 5, 2025 23:50
@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
アプリが使いやすくなる提案であれば大歓迎です!
今回は的を得ている意見だと思ったので直していますが、違うと思ったときは普通に反論するのでお気になさらず。

というわけで修正しましたので、確認お願いします!

Copy link
Copy Markdown
Contributor

@masyuko0222 masyuko0222 left a comment

Choose a reason for hiding this comment

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

@kitarou888
動作確認OKです〇

気になる点を少しコメントしましたので、ご確認お願いいたしますー。

Comment on lines +33 to +26
# only_me=true の場合、user_id カラムを持たないプラクティスとユーザーは対象外とする
if only_me
searchables = searchables.select do |searchable|
%w[User Practice].include?(searchable.class.name) ? false : searchable.user_id == current_user.id
end
end
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.

コメントよりも説明的な変数名を使った方が、コードの意図がより伝わりやすくなるのかなと思いました。

また、searchables から User と Practice クラスを除外し、その後に current_user.id と一致するものを絞り込む処理で書いた方が、流れがシンプルで読みやすくなるかなと思いました。

以下のイメージです。

if only_me
  not_posted_classes = %w[User Practice]
  searchables = searchables.reject { |s| s.class.name.in?(not_posted_classes) }
                           .select { |s| s.user_id == current_user.id }
end


# 他のユーザーの投稿が除外されていることを確認
all_results = Searcher.search(word: 'テスト', only_me: false, current_user:, document_type: :reports)
other_user_results = all_results.select { |searchable| searchable.user_id == other_user.id }
Copy link
Copy Markdown
Contributor

@masyuko0222 masyuko0222 Jul 7, 2025

Choose a reason for hiding this comment

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

assert(result.all? { |searchable| searchable.user_id == current_user.id })

で「結果の全てがcurrent_userの投稿である」ことが確認できているので、
あらためて「他ユーザーの投稿が含まれていない」ことを別でチェックする必要はないと思います。

その代わりにUserPracticeクラスのオブジェクトが検索結果に混ざっていないことは別途確認してもいいのではないでしょうか?

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/models/searcher_test.rb (1)

208-208: 未使用変数を削除してください。

other_user変数が宣言されていますが、テスト内で使用されていません。

  test 'search only myself' do
    current_user = users(:komagata)
-   other_user = users(:kimura)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8c22e0 and c893f92.

📒 Files selected for processing (2)
  • app/models/searcher.rb (2 hunks)
  • test/models/searcher_test.rb (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/models/searcher.rb
🧰 Additional context used
🧠 Learnings (1)
test/models/searcher_test.rb (7)
Learnt from: masyuko0222
PR: fjordllc/bootcamp#8277
File: test/models/searcher_test.rb:0-0
Timestamp: 2025-07-07T12:46:01.650Z
Learning: テストにおいて、`result.all? { |condition| }` でコレクションの全要素が条件を満たすことを確認できれば、その条件を満たさない要素が含まれていないことも論理的に保証されるため、追加のアサーションは冗長となる。
Learnt from: mousu-a
PR: fjordllc/bootcamp#8566
File: app/views/pair_works/_body.html.slim:3-4
Timestamp: 2025-07-01T04:26:24.636Z
Learning: PairWorkモデルにおいて、pair_work.solved?がtrueを返す場合、buddy_idは必ず存在することがビジネスロジックで保証されている。そのため、solved?の条件分岐内でのUser.find(pair_work.buddy_id)は安全に使用できる。
Learnt from: mousu-a
PR: fjordllc/bootcamp#8566
File: app/notifiers/activity_notifier.rb:357-373
Timestamp: 2025-07-01T04:30:19.565Z
Learning: matching_pair_workメソッドは、ペア確定時に送信される通知のため、pair_work.buddy_idは必ず存在することがビジネスロジックで保証されている。そのため、User.find(pair_work.buddy_id)でのエラーハンドリングは不要。
Learnt from: e-yanagita-gs
PR: fjordllc/bootcamp#8771
File: app/controllers/welcome_controller.rb:57-57
Timestamp: 2025-06-30T01:07:46.192Z
Learning: プロジェクトでは、仕様上データの存在が保証されている場合、nil処理を省略することがある。特にFAQ表示のような特定機能に特化したPRでは、データの存在を前提とした実装が採用される。
Learnt from: hirokiej
PR: fjordllc/bootcamp#8740
File: app/helpers/reports_helper.rb:56-64
Timestamp: 2025-06-29T03:44:15.179Z
Learning: このプロジェクト(fjordllc/bootcamp)では、ja.ymlファイルで一部の単語や文章のみI18n対応されているが、多くのテキストは日本語でハードコーディングされており、完全な国際化対応は行われていない。新しい機能でもI18n対応は不要と判断される。
Learnt from: tyrrell-IH
PR: fjordllc/bootcamp#8807
File: app/views/welcome/job_support.html.slim:391-392
Timestamp: 2025-06-21T22:30:20.116Z
Learning: このプロジェクトにはRailsの組み込みmarkdownヘルパが利用できないため、markdownのHTML変換には自前でヘルパを実装する必要がある。
Learnt from: su-su-su-su
PR: fjordllc/bootcamp#0
File: :0-0
Timestamp: 2025-07-07T05:28:03.676Z
Learning: fjordllc/bootcampプロジェクトでは、fixtureファイル内のERB構文で改行制御文字(-)は使用せず、標準的な<% %>と<%= %>のみを使用する方針が統一されている。<% -%>や<%- %>を使用するとSyntaxErrorが発生する。
⏰ 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
🔇 Additional comments (1)
test/models/searcher_test.rb (1)

20-201: メソッドシグネチャの更新が適切に実装されています。

全てのテストケースでSearcher.searchの呼び出しが位置引数からキーワード引数(word:)に正しく更新されています。変更が一貫して適用されており、問題ありません。

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from c893f92 to 8650734 Compare July 10, 2025 12:44
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

🧹 Nitpick comments (1)
app/controllers/searchables_controller.rb (1)

10-10: キーワード引数の使用により可読性が向上しました

Searcherクラスのメソッドシグネチャに合わせたキーワード引数の使用は明確で良い変更です。only_meパラメータの追加も適切に実装されています。

ただし、より厳密にするなら、チェックボックスのパラメータを明示的にbooleanに変換することを検討してください。

-    searchables = Searcher.search(word: @word, only_me: params[:only_me], current_user:, document_type: @document_type)
+    searchables = Searcher.search(word: @word, only_me: !!params[:only_me], current_user:, document_type: @document_type)

または、より明示的に:

-    searchables = Searcher.search(word: @word, only_me: params[:only_me], current_user:, document_type: @document_type)
+    searchables = Searcher.search(word: @word, only_me: params[:only_me] == '1', current_user:, document_type: @document_type)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c893f92 and 8650734.

📒 Files selected for processing (13)
  • app/controllers/searchables_controller.rb (1 hunks)
  • app/javascript/stylesheets/application.sass (0 hunks)
  • app/javascript/stylesheets/application/blocks/header/_header-search.sass (0 hunks)
  • app/javascript/stylesheets/atoms/_a-text-input.sass (0 hunks)
  • app/models/searcher.rb (1 hunks)
  • app/views/application/header/_header_links.html.slim (2 hunks)
  • app/views/application/header/_header_search.html.slim (1 hunks)
  • app/views/searchables/index.html.slim (1 hunks)
  • test/models/searcher_test.rb (12 hunks)
  • test/models/user_test.rb (1 hunks)
  • test/system/admin/users/password_test.rb (1 hunks)
  • test/system/current_user/password_test.rb (1 hunks)
  • test/system/searchables_test.rb (6 hunks)
💤 Files with no reviewable changes (3)
  • app/javascript/stylesheets/application.sass
  • app/javascript/stylesheets/atoms/_a-text-input.sass
  • app/javascript/stylesheets/application/blocks/header/_header-search.sass
🚧 Files skipped from review as they are similar to previous changes (9)
  • test/system/admin/users/password_test.rb
  • test/system/current_user/password_test.rb
  • test/system/searchables_test.rb
  • test/models/user_test.rb
  • app/views/searchables/index.html.slim
  • app/views/application/header/_header_links.html.slim
  • app/models/searcher.rb
  • test/models/searcher_test.rb
  • app/views/application/header/_header_search.html.slim
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.rb`: # refactoring - まずFat Controllerを避け、次にFat Modelを避ける。 - Serviceクラスの乱用を...

**/*.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の機能があるので使う)

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • app/controllers/searchables_controller.rb
🧬 Code Graph Analysis (1)
app/controllers/searchables_controller.rb (1)
app/models/searcher.rb (1)
  • search (16-32)
⏰ 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

@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 77fca61 to 04d2fcd Compare July 20, 2025 00:05
@kitarou888 kitarou888 force-pushed the feature/searchable-filtering-login-user branch from 04d2fcd to 31f2eaf Compare July 20, 2025 00:21
@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
修正が遅くなりましたが完了しましたので、再レビューのほどお願いします!

Copy link
Copy Markdown
Contributor

@masyuko0222 masyuko0222 left a comment

Choose a reason for hiding this comment

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

自分からはapproveいたします!

@kitarou888
Copy link
Copy Markdown
Contributor Author

@masyuko0222
承知しました!
このたびはレビューいただきありがとうございました🙏

@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 ff53b48 into main Jul 23, 2025
7 checks passed
@komagata komagata deleted the feature/searchable-filtering-login-user branch July 23, 2025 12:18
@github-actions github-actions bot mentioned this pull request Jul 23, 2025
87 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jan 18, 2026
3 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.

4 participants