Skip to content

Test/improve coverage#111

Merged
machida merged 2 commits intomainfrom
test/improve-coverage
Dec 3, 2025
Merged

Test/improve coverage#111
machida merged 2 commits intomainfrom
test/improve-coverage

Conversation

@machida
Copy link
Copy Markdown
Owner

@machida machida commented Dec 2, 2025

Summary by CodeRabbit

  • Tests
    • 診断エンドポイントのテストスイートを追加し、認証、環境設定、画像アップロード機能の検証が含まれます
    • サイト設定サービスの包括的なテストカバレッジを追加し、デフォルト値、取得、設定、リセット機能をカバーしています
    • 並行テスト実行中のカバレッジデータ統合機能を改善しました

✏️ Tip: You can customize this high-level summary in your review settings.

- SimpleCov並列実行サポート追加
  - use_merging/merge_timeout設定でワーカー間のカバレッジをマージ
  - parallelize_setup/teardownコールバックで各ワーカーに一意なcommand_nameを設定
- Admin::DiagnosticsControllerのテスト追加 (6テスト)
  - image_upload_check エンドポイントの全機能をカバー
  - 認証、JSON形式、環境情報、VIPSステータス、GCS設定を検証

カバレッジ改善: 2.29% → 75.63% (+73.34%)
- Add 12 tests covering all methods (defaults, get, set, all_settings, update_settings, reset_to_defaults!)
- Test both symbol and string key handling
- Verify invalid key filtering in update_settings
- Test fallback to defaults when DB values don't exist
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 2, 2025

Walkthrough

Rails 8プロジェクトの診断機能とサイト設定機能をテストするテストスイートが追加され、並列テスト実行環境でのカバレッジ統合対応が実装されました。診断エンドポイント、設定サービス、認証を包括的にカバーします。

Changes

Cohort / File(s) 概要
診断コントローラーテスト
test/controllers/admin/diagnostics_controller_test.rb
Admin::DiagnosticsControllerTestスイートを新規追加。認証検証、画像アップロード診断エンドポイント(image_upload_check)のレスポンス構造・環境設定・VIPS/GCS状態の確認テストを実装
サイト設定サービステスト
test/services/site_setting_service_test.rb
SiteSettingServiceの包括的テストスイートを新規追加。デフォルト値管理、ゲッター・セッター、一括更新、リセット機能のテストケースを包含
テストヘルパー並列化対応
test/test_helper.rb
SimpleCovカバレッジ統合の並列テスト対応を実装。マージタイムアウト設定とワーカーID追跡によるカバレッジデータの一貫性確保

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

レビュー時の注目ポイント:

  • 認証テストが正しくセッション削除・リダイレクト確認を実施しているか(セキュリティ観点)
  • 環境別設定(development時のGCS設定)の検証ロジックが適切か
  • SimpleCovの並列化設定でCI環境の環境変数判定が正確か
  • テストケースがRails 8の推奨パターン(test_should_*命名規約)に準拠しているか

Possibly related PRs

Poem

🧪 診断は明確に、設定は堅牢に、
テストたちは並列に走り、
カバレッジ統合で真実の姿が、✨
Rails 8のコード品質が光る 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive プルリクエストのタイトルは、テストスイートの追加とカバレッジ改善という主要な変更内容を部分的に反映していますが、具体的な内容が不明確です。 より具体的なタイトルに変更してください。例えば「Add diagnostics and site setting service tests with coverage merge support」のようにテスト追加の具体的な対象を明記することをお勧めします。
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 test/improve-coverage

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.

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 19851828113

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+74.3%) to 76.523%

Totals Coverage Status
Change from base Build 19851176380: 74.3%
Covered Lines: 644
Relevant Lines: 818

💛 - Coveralls

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/controllers/admin/diagnostics_controller_test.rb (1)

4-7: ログイン成功の検証を追加することを推奨します。

setupメソッド内でログインが成功したかの検証がないため、ログインが失敗した場合にテストが混乱したエラーメッセージで失敗する可能性があります。また、test_helper.rbで定義されているTestConfig::TEST_ADMIN_PASSWORDの使用も検討してください。

以下のように修正することを推奨します:

 setup do
   @admin = admins(:admin)
   post admin_login_path, params: { email: @admin.email, password: "password123" }
+  assert_response :redirect
 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 f973046 and 7946c56.

📒 Files selected for processing (3)
  • test/controllers/admin/diagnostics_controller_test.rb (1 hunks)
  • test/services/site_setting_service_test.rb (1 hunks)
  • test/test_helper.rb (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.rb

📄 CodeRabbit inference engine (CLAUDE.md)

Follow Rails Omakase RuboCop standards (2 spaces, snake_case, Admin:: namespace) and use bundle exec rubocop, only using -a/-A flags when necessary.

Use Rails Omakase RuboCop style guide with 2 spaces, snake_case, and Admin:: namespace conventions; run bundle exec rubocop and use -a/-A flags only when necessary

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
test/**/*.{rb,js,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Reference .spec-- classes in Playwright/MiniTest and update test/support/selectors.rb when adding or changing test selector classes.

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
**/*.{rb,js,ts,jsx,tsx,css,scss,html,erb}

📄 CodeRabbit inference engine (CLAUDE.md)

Implement code to explain 'How', tests to explain 'What', and commits to explain 'Why'. Add newline at end of files and prohibit trailing whitespace.

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
test/**/*_test.rb

📄 CodeRabbit inference engine (CLAUDE.md)

Name test files by feature (e.g., admin_creates_article_test.rb) and use .spec-- classes to locate elements.

Files:

  • test/services/site_setting_service_test.rb
  • test/controllers/admin/diagnostics_controller_test.rb
**/*.{erb,html,css,rb}

📄 CodeRabbit inference engine (AGENTS.md)

When adding or modifying .spec-- test selector classes, also update test/support/selectors.rb

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
**/*.{rb,js,ts,jsx,tsx,erb,html,css}

📄 CodeRabbit inference engine (AGENTS.md)

Follow design principles: code should be predictable, reusable, maintainable, and extensible; add comments explaining 'Why not' for complex decisions; ensure files end with newline and contain no trailing whitespace

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
test/**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Name test files by feature unit (e.g., admin_creates_article_test.rb) and use .spec-- classes to select page elements

Files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: machida/mb PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T17:51:13.963Z
Learning: Manage tests in `test/` directory (browser tests in `test/system`, test selectors in `test/support/selectors.rb`), long-form documentation in `docs/`, and schema changes in `db/migrate`.
📚 Learning: 2025-12-01T17:51:13.963Z
Learnt from: CR
Repo: machida/mb PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T17:51:13.963Z
Learning: Manage tests in `test/` directory (browser tests in `test/system`, test selectors in `test/support/selectors.rb`), long-form documentation in `docs/`, and schema changes in `db/migrate`.

Applied to files:

  • test/services/site_setting_service_test.rb
  • test/test_helper.rb
  • test/controllers/admin/diagnostics_controller_test.rb
📚 Learning: 2025-12-01T17:51:13.963Z
Learnt from: CR
Repo: machida/mb PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T17:51:13.963Z
Learning: Applies to test/**/*.{rb,js,ts} : Reference `.spec--` classes in Playwright/MiniTest and update `test/support/selectors.rb` when adding or changing test selector classes.

Applied to files:

  • test/test_helper.rb
📚 Learning: 2025-12-01T17:51:40.093Z
Learnt from: CR
Repo: machida/mb PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-01T17:51:40.093Z
Learning: Applies to **/*.{erb,html,css,rb} : When adding or modifying `.spec--` test selector classes, also update `test/support/selectors.rb`

Applied to files:

  • test/test_helper.rb
📚 Learning: 2025-12-01T17:51:13.963Z
Learnt from: CR
Repo: machida/mb PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T17:51:13.963Z
Learning: Applies to test/**/*_test.rb : Name test files by feature (e.g., `admin_creates_article_test.rb`) and use `.spec--` classes to locate elements.

Applied to files:

  • test/controllers/admin/diagnostics_controller_test.rb
📚 Learning: 2025-12-01T17:51:40.093Z
Learnt from: CR
Repo: machida/mb PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-01T17:51:40.093Z
Learning: Applies to test/**/*.rb : Name test files by feature unit (e.g., `admin_creates_article_test.rb`) and use `.spec--` classes to select page elements

Applied to files:

  • test/controllers/admin/diagnostics_controller_test.rb
🧬 Code graph analysis (1)
test/services/site_setting_service_test.rb (1)
app/services/site_setting_service.rb (3)
  • all_settings (15-19)
  • update_settings (21-25)
  • reset_to_defaults! (27-31)
🔇 Additional comments (14)
test/test_helper.rb (2)

13-17: 並列テスト実行のカバレッジマージング設定が適切です。

SimpleCovのuse_mergingmerge_timeout設定により、並列ワーカー間でカバレッジデータが正しく統合されます。1時間のタイムアウトは十分な余裕があります。


39-49: 並列テスト対応のSimpleCov設定が正しく実装されています。

parallelize_setupでワーカーごとに一意のコマンド名を設定し、parallelize_teardownでカバレッジ結果を確定させる実装は、SimpleCovの推奨パターンに従っています。

test/services/site_setting_service_test.rb (7)

4-6: テストの分離が適切に実装されています。

setupでのSiteSetting.delete_allにより、各テストがクリーンな状態から開始されるため、テスト間の干渉が防止されます。


8-17: デフォルト設定のテストが網羅的です。

6つの設定項目すべてに対して期待値が検証されており、テスト環境の設定値が正しく定義されていることを確認しています。


19-24: データベース値の取得と文字列/シンボル両対応のテストが適切です。

getメソッドが永続化された値を正しく取得し、文字列キーとシンボルキーの両方で動作することを確認しています。


26-51: getsetメソッドの各種シナリオが十分にカバーされています。

デフォルト値へのフォールバック、存在しないキーの処理、データベースへの保存、文字列/シンボルキーの両対応が適切にテストされています。


53-67: all_settingsメソッドのテストが包括的です。

カスタム値とデフォルト値の混在、すべての期待されるキーの存在、戻り値の型が適切に検証されています。


69-103: update_settingsメソッドのテストがセキュリティと機能の両面で適切です。

一括更新の成功ケース、不正なキーの無視(セキュリティ重要)、文字列キー対応がすべて検証されており、堅牢性が確保されています。


105-126: reset_to_defaults!メソッドの両方のシナリオが適切にテストされています。

既存のカスタム値のリセットと、存在しない設定の新規作成の両方が検証されており、メソッドの完全な動作が保証されています。

test/controllers/admin/diagnostics_controller_test.rb (5)

9-12: 基本的なエンドポイントアクセステストが適切です。

ルートの存在と成功レスポンスの返却を確認するシンプルなスモークテストとして機能しています。


14-23: JSONレスポンス構造の検証が適切です。

診断情報として必要な4つのキー(environment, vips_available, gcs_configured, timestamp)の存在を確認しており、APIの契約が守られていることを検証しています。


25-30: 環境情報の正確性が検証されています。

診断エンドポイントがテスト環境を正しく報告することを確認しており、環境別の動作確認に役立ちます。


32-37: VIPS状態の基本的な存在確認が行われています。

vips_availableフィールドが存在し、nilでないことを検証しています。テスト環境でのVIPSインストール状況に依存しないため、適切な検証レベルです。


50-54: 認証要件のテストが適切に実装されています。

ログアウト後のアクセスがログインページにリダイレクトされることを確認しており、管理画面エンドポイントのセキュリティが保証されています。

Comment on lines +39 to +48
test "image_upload_check includes gcs configuration in development" do
get admin_diagnostics_image_upload_check_path
json = JSON.parse(response.body)

assert_equal "development", json["gcs_configured"]["status"]
assert_equal "GCS not required in development", json["gcs_configured"]["message"]
assert_equal false, json["gcs_configured"]["project_id"]
assert_equal false, json["gcs_configured"]["bucket"]
assert_equal false, json["gcs_configured"]["credentials"]
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

環境判定のテストロジックに不整合があります。

テストは"test"環境で実行されていますが(Line 29で確認済み)、Line 43-44では"development"環境のレスポンスを期待しています。これは以下のいずれかの問題を示唆しています:

  1. テスト名が誤っており、"in test or development"とすべき
  2. アサーションが誤っており、"test"環境の応答を検証すべき
  3. コントローラーが"test"と"development"を同等に扱っている場合、テスト名とアサーションを明確にすべき

コントローラーの実装を確認し、テスト環境での実際のレスポンスに合わせてアサーションを修正してください:

-  test "image_upload_check includes gcs configuration in development" do
+  test "image_upload_check includes gcs configuration in non-production" do
     get admin_diagnostics_image_upload_check_path
     json = JSON.parse(response.body)
 
-    assert_equal "development", json["gcs_configured"]["status"]
-    assert_equal "GCS not required in development", json["gcs_configured"]["message"]
+    # Verify the actual status returned in test environment
+    assert_includes ["development", "test"], json["gcs_configured"]["status"]
+    assert_not_nil json["gcs_configured"]["message"]
     assert_equal false, json["gcs_configured"]["project_id"]
     assert_equal false, json["gcs_configured"]["bucket"]
     assert_equal false, json["gcs_configured"]["credentials"]
   end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test "image_upload_check includes gcs configuration in development" do
get admin_diagnostics_image_upload_check_path
json = JSON.parse(response.body)
assert_equal "development", json["gcs_configured"]["status"]
assert_equal "GCS not required in development", json["gcs_configured"]["message"]
assert_equal false, json["gcs_configured"]["project_id"]
assert_equal false, json["gcs_configured"]["bucket"]
assert_equal false, json["gcs_configured"]["credentials"]
end
test "image_upload_check includes gcs configuration in non-production" do
get admin_diagnostics_image_upload_check_path
json = JSON.parse(response.body)
# Verify the actual status returned in test environment
assert_includes ["development", "test"], json["gcs_configured"]["status"]
assert_not_nil json["gcs_configured"]["message"]
assert_equal false, json["gcs_configured"]["project_id"]
assert_equal false, json["gcs_configured"]["bucket"]
assert_equal false, json["gcs_configured"]["credentials"]
end
🤖 Prompt for AI Agents
In test/controllers/admin/diagnostics_controller_test.rb around lines 39 to 48,
the test is executed in the "test" environment but currently asserts
"development" for the gcs_configured status and message; update the assertions
to match the actual test environment by changing the expected status from
"development" to "test" and the expected message from "GCS not required in
development" to an appropriate "GCS not required in test" (or rename the test to
reflect development if you intend to simulate development); ensure the other
assertions (project_id, bucket, credentials being false) remain as-is.

@machida machida merged commit f4076d9 into main Dec 3, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 1, 2026
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.

2 participants