Skip to content

リンクチェッカーのテストがローカルで落ちる問題を解決#9248

Merged
machida merged 2 commits intomainfrom
fix-tests
Oct 16, 2025
Merged

リンクチェッカーのテストがローカルで落ちる問題を解決#9248
machida merged 2 commits intomainfrom
fix-tests

Conversation

@machida
Copy link
Copy Markdown
Member

@machida machida commented Oct 9, 2025

  • domainがblankだった場合にfalseを返すようにした
  • テストで使う invalid のドメインは # RFC 2606で予約済み のものを使うようにした

Summary by CodeRabbit

  • バグ修正
    • 空のドメイン入力を検出して早期に false を返すようにし、不要な DNS ルックアップを回避。無効入力時の安定性とエラーハンドリングを改善し、公開 API や外部挙動に変更なし。
  • テスト
    • 無効ドメインのテスト入力を予約ドメイン(invalid.invalid)に更新し、検証の信頼性を向上。

@github-actions github-actions bot requested a review from komagata October 9, 2025 15:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 9, 2025

Walkthrough

空文字ドメインの場合に valid_domain? が早期に false を返すガード句を追加。非空の場合は従来どおりDNS解決を試み、成功で trueResolv::ResolvError 発生時に false を返す。テストの無効ドメインを予約済みドメインに変更。

Changes

Cohort / File(s) Summary
Link Checker validation
app/models/link_checker/checker.rb
valid_domain?domain.blank? をチェックして早期に false を返すガードを追加。既存のDNS解決フローと Resolv::ResolvError の rescue は維持。署名変更なし。
Tests
test/models/link_checker/checker_test.rb
無効ドメインのテスト入力を invalid-domain.co から RFC2606 予約済みの invalid.invalid に変更。アサーションは不変。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as 呼び出し元
  participant Checker as LinkChecker::Checker
  participant DNS as DNS Resolver

  Caller->>Checker: valid_domain?(domain)
  alt domain.blank?(空)
    Note over Checker: ガード句で早期リターン
    Checker-->>Caller: false
  else domain が存在
    Checker->>DNS: resolve(domain)
    alt 解決成功
      DNS-->>Checker: resolved
      Checker-->>Caller: true
    else Resolv::ResolvError(解決失敗)
      Note over Checker: rescue 節で false を返す
      Checker-->>Caller: false
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Suggested reviewers

  • komagata

Poem

ぽんと跳ねる小さなウサギだよ🐇
空のドメインは「だめよ」と一言で止める
無駄な問合せはもうおしまい
テストは静かに予約域で笑う
ぴょん、変更は小さくて確かだ

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning プルリクエストの説明は、変更内容について基本的な情報を提供していますが、リポジトリの説明テンプレートで必須とされている構造に従っていません。テンプレートで要求されている「Issue番号」「概要」セクション、「変更確認方法」(実行手順を含む)、「Screenshot」(変更前後)などの重要なセクションが欠落しており、説明は2行の箇条書きのみとなっています。提供されたテキストは変更内容を説明していますが、要求されたテンプレート形式と比べて大幅に不完全です。 プルリクエストの説明を指定されたテンプレートに従って記入してください。Issue番号の追加、「概要」「変更確認方法」「Screenshot」などの各セクションを埋め入れる必要があります。特に「変更確認方法」では具体的な手順を、「Screenshot」では変更前後の動作や状態を示すことで、レビュアーがこの変更を確認しやすくなります。
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed プルリクエストのタイトル「リンクチェッカーのテストがローカルで落ちる問題を解決」は、変更セットの主な目的と完全に一致しており、リンクチェッカーのテスト失敗問題を修正する内容を明確に説明しています。タイトルは簡潔で具体的であり、変更ログを閲覧するチームメンバーがこのプルリクエストの主要な目的を素早く理解できます。プロダクション環境でのテスト実行失敗の問題解決という主要な変更が正確に伝わっています。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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 fix-tests

📜 Recent 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 7f3d13c and fc4613b.

📒 Files selected for processing (1)
  • test/models/link_checker/checker_test.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/link_checker/checker_test.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/link_checker/checker_test.rb
🧬 Code graph analysis (1)
test/models/link_checker/checker_test.rb (1)
app/models/link_checker/checker.rb (1)
  • valid_domain? (37-44)
⏰ 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/link_checker/checker_test.rb (1)

97-100: RFC 2606 予約済みドメインの使用は適切です

invalid.invalid への変更は良い改善です。RFC 2606 で予約されているドメインを使用することで、以前の invalid-domain.co が将来実際に登録される可能性を排除できます。空文字列のテストと合わせて、実装の domain.blank? ガード句と無効なドメイン名の両方のケースを適切にカバーしています。

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.1)
test/models/link_checker/checker_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.1/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.81.1/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.1/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.1/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/config_store.rb:34:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/config_store.rb:29:in apply_options!'
/var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:167:in act_on_options' /var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:49:in block in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:87:in profile_if_needed' /var/lib/gems/3.1.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:45:in run'
/var/lib/gems/3.1.0/gems/rubocop-1.81.1/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.

@machida machida self-assigned this Oct 9, 2025
@machida machida removed the request for review from komagata October 16, 2025 00:57
@machida machida merged commit 883044e into main Oct 16, 2025
3 checks passed
@machida machida deleted the fix-tests branch October 16, 2025 03:08
@github-actions github-actions bot mentioned this pull request Oct 16, 2025
12 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