Skip to content

Company#logo_urlのフレーキーテストを修正#9290

Merged
machida merged 1 commit intomainfrom
logo_url
Nov 5, 2025
Merged

Company#logo_urlのフレーキーテストを修正#9290
machida merged 1 commit intomainfrom
logo_url

Conversation

@machida
Copy link
Copy Markdown
Member

@machida machida commented Nov 5, 2025

Summary by CodeRabbit

リリースノート

このリリースには、エンドユーザーに対する変更はございません。

  • Tests
    • テストインフラストラクチャの改善

@github-actions github-actions bot requested a review from komagata November 5, 2025 12:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 5, 2025

ウォークスルー

テストファイルに新しいロゴヘルパーモジュールを導入し、会社テストのロゴリセット機能を実装しました。LogoHelper モジュールが新規作成され、CompanyTest クラスに統合されて、テスト実行時のロゴ添付を初期化します。

変更内容

コホート / ファイル 変更概要
新しいテストヘルパーモジュール
test/supports/logo_helper.rb
LogoHelper モジュールを新規作成。reset_logo(company, logo_filename) メソッドを追加し、テストフィクスチャからJPEGロゴを会社に添付するユーティリティを提供
CompanyTest統合
test/models/company_test.rb
LogoHelper モジュールのrequireとincludeを追加。テスト実行時にロゴURLを取得する前に reset_logo を呼び出し

推定コードレビュー時間

🎯 2 (Simple) | ⏱️ ~8 分

  • 確認すべき点: reset_logo メソッドのファイルパス解決ロジックが正しいことを確認
  • 確認すべき点: テストフィクスチャディレクトリ構造との整合性確認

関連する可能性のあるPR

推奨レビュアー

  • komagata

ポエム

🐰 ロゴがふらふら揺れていたね
ヘルパーさんが駆けつけて
テストを整えてくれました
今は安定、ぴったり固定!
兎の魔法でバグ退治 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning プルリクエストの説明が提供されていません。リポジトリのテンプレートで要求されている複数のセクションが完全に不足しています。 提供されているテンプレートに従い、Issue番号、概要、変更確認方法、スクリーンショットなどの必須セクションを追加してください。
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは変更の主な目的を明確に表しており、フレーキーテストの修正というコンテキストに適切に関連しています。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch logo_url

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.81.7)
test/supports/logo_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.81.7/lib/rubocop/config_loader_resolver.rb:310:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/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.81.7/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/g

... [truncated 255 characters] ...

fig_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_store.rb:34:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_store.rb:29:in apply_options!'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:167:in act_on_options' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:49:in block in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:87:in profile_if_needed' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:45:in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/exe/rubocop:15:in <top (required)>' /usr/local/bin/rubocop:25:in load'
/usr/local/bin/rubocop:25:in `

'

test/models/company_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.81.7/lib/rubocop/config_loader_resolver.rb:310:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/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.81.7/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/g

... [truncated 255 characters] ...

fig_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_store.rb:34:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/config_store.rb:29:in apply_options!'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:167:in act_on_options' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:49:in block in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:87:in profile_if_needed' /var/lib/gems/3.1.0/gems/rubocop-1.81.7/lib/rubocop/cli.rb:45:in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.7/exe/rubocop:15:in <top (required)>' /usr/local/bin/rubocop:25:in load'
/usr/local/bin/rubocop:25:in `

'


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.

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)
test/supports/logo_helper.rb (1)

4-12: 全体的に良い実装ですが、ファイルハンドリングの改善を検討してください

実装は機能的には正しいですが、以下の点を検討してください:

  1. ファイルハンドリングのパターン: File.openを使用していますが、File.binreadを使用するとよりクリーンです。ActiveStorageが内部でファイルを閉じるはずですが、明示的にファイルハンドルを渡さない方が安全です。

  2. エラーハンドリング: フィクスチャファイルが存在しない場合、不明瞭なエラーが発生します。File.exist?でバリデーションを追加するか、より明確なエラーメッセージを提供することを検討してください。

以下のように改善できます:

 def reset_logo(company, logo_filename)
   filename = "#{logo_filename}.jpg"
   path = Rails.root.join('test/fixtures/files/companies/logos', filename)
   company.logo.attach(
-    io: File.open(path, 'rb'),
+    io: StringIO.new(File.binread(path)),
     filename:,
     content_type: 'image/jpeg'
   )
 end

または、よりシンプルに:

 def reset_logo(company, logo_filename)
   filename = "#{logo_filename}.jpg"
   path = Rails.root.join('test/fixtures/files/companies/logos', filename)
   company.logo.attach(
-    io: File.open(path, 'rb'),
+    io: File.binread(path),
     filename:,
     content_type: 'image/jpeg'
   )
 end
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d19c9b and 150e2fc.

📒 Files selected for processing (2)
  • test/models/company_test.rb (1 hunks)
  • test/supports/logo_helper.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/models/company_test.rb
  • test/supports/logo_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/models/company_test.rb
  • test/supports/logo_helper.rb
🧠 Learnings (3)
📓 Common learnings
Learnt from: jun-kondo
Repo: fjordllc/bootcamp PR: 0
File: :0-0
Timestamp: 2025-07-23T20:42:19.974Z
Learning: fjordllc/bootcampプロジェクトでは、hタグ(見出し)の文言は日本語でハードコーディングする方針が確立されており、I18n対応は行わない。例:app/views/welcome/logo.html.slimでh2、h3タグが日本語でハードコーディングされている。
Learnt from: Miya096jp
Repo: fjordllc/bootcamp PR: 9102
File: app/controllers/mentor/buzzes_controller.rb:0-0
Timestamp: 2025-09-04T01:39:22.261Z
Learning: fjordllc/bootcamp プロジェクトでは、更新処理の成功時の通知メッセージについて、I18n を使用せずに日本語文字列を直接記述する方針で一貫性を保っている。
Learnt from: komagata
Repo: fjordllc/bootcamp PR: 9101
File: app/notifiers/discord_notifier.rb:131-135
Timestamp: 2025-09-12T21:18:00.834Z
Learning: Rails アップグレードPRにおいて、product_review_not_completed メソッドの webhook URL 設定の shared フォールバック追加も、設定システム全体の変更として別PRで対応すべきである。
Learnt from: hirokiej
Repo: fjordllc/bootcamp PR: 8740
File: app/helpers/reports_helper.rb:56-64
Timestamp: 2025-06-29T03:44:15.179Z
Learning: このプロジェクト(fjordllc/bootcamp)では、ja.ymlファイルで一部の単語や文章のみI18n対応されているが、多くのテキストは日本語でハードコーディングされており、完全な国際化対応は行われていない。新しい機能でもI18n対応は不要と判断される。
📚 Learning: 2025-09-08T04:55:46.649Z
Learnt from: sharoa119
Repo: fjordllc/bootcamp PR: 8711
File: db/schema.rb:0-0
Timestamp: 2025-09-08T04:55:46.649Z
Learning: In this PR, the removal of length limits from companies.name and companies.website columns in db/schema.rb was unintentional - it was a case of accidentally lost constraints that needed to be restored to their original limits, not a deliberate design change.

Applied to files:

  • test/models/company_test.rb
📚 Learning: 2025-08-25T07:23:54.802Z
Learnt from: sjabcdefin
Repo: fjordllc/bootcamp PR: 9090
File: app/javascript/user_sns.js:0-0
Timestamp: 2025-08-25T07:23:54.802Z
Learning: app/javascript/user_sns.js の会社ロゴ表示において、_list_user.json.builder の構造により user.company.logo_url が存在する場合は必ず user.company.url も存在することが API レスポンス構造で保証されている

Applied to files:

  • test/models/company_test.rb
🧬 Code graph analysis (2)
test/models/company_test.rb (2)
app/models/company.rb (1)
  • include (3-22)
test/supports/logo_helper.rb (1)
  • reset_logo (4-12)
test/supports/logo_helper.rb (1)
app/controllers/welcome_controller.rb (1)
  • logo (57-57)
⏰ 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/company_test.rb (1)

4-10: LGTM! フレーキーテスト修正のアプローチが適切です

テストの前にreset_logoを呼び出してロゴの添付状態を確実にリセットすることで、テストの一貫性が保証されます。これはフレーキーテストを修正する標準的で効果的なアプローチです。

@machida machida self-assigned this Nov 5, 2025
@machida machida removed the request for review from komagata November 5, 2025 13:11
@machida machida merged commit 185ad6e into main Nov 5, 2025
7 checks passed
@machida machida deleted the logo_url branch November 5, 2025 14:30
@github-actions github-actions bot mentioned this pull request Nov 5, 2025
16 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.

1 participant