Skip to content

test(search): strengthen FieldRegistry coverage (closes #9)#17

Merged
kevinelliott merged 1 commit into
developfrom
fix/field-registry-test-coverage
May 28, 2026
Merged

test(search): strengthen FieldRegistry coverage (closes #9)#17
kevinelliott merged 1 commit into
developfrom
fix/field-registry-test-coverage

Conversation

@kevinelliott

Copy link
Copy Markdown
Collaborator

Closes #9.

Context

Issue #9 was filed 2026-01-24 reporting "Multiple test failures for the search field registry and related services tests." Investigating today, all 53 tests in test/services/search/ pass cleanly (verified across three consecutive runs). The original failures appear to have been resolved progressively across e48a97b ("fix: resolve test failures for CI"), PR #13's review rounds, and PR #15 (yesterday).

Rather than close #9 with no value delivered, this PR fills the coverage gaps that were left behind. The existing tests covered only the Aircraft model and missed several behaviours that matter for downstream consumers (autocomplete, QueryTranslator's field validation, the registry's own resilience).

Changes

test/services/search/field_registry_test.rb — 6 new tests, 23 new assertions, no production code touched.

New test What it pins down
Cross-model fields_for expectations Each SEARCHABLE_MODEL (Operator, AircraftType, Airport, Country, Manufacturer, Route) returns its declared filterable_attributes. A single hash assertion so regressions surface here, not in downstream search tests.
fields_for returns Symbols The registry's contract; meilisearch_attribute_for relies on to_sym round-trips.
fields_for rescues StandardError The registry swallows model errors so an indexing misconfiguration in one model doesn't take down autocomplete. Verified via a singleton-method swap (Minitest 6 dropped Object#stub; an ensure block restores the original).
meilisearch_attribute_for accepts Symbol input Matches the dual-input coverage valid_field? already had.
suggest_fields sort order The method explicitly sorts by :value; previously only presence was checked.
suggest_fields :display humanisation humanize_field_name calls titleize; was completely untested.

Test plan

  • ./bin/rails test test/services/search/field_registry_test.rb — 18 runs, 0 failures, 44 assertions.
  • ./bin/rails test test/services/search/ — 59 runs, 0 failures, 133 assertions; three consecutive runs all green.
  • bundle exec rubocop test/services/search/field_registry_test.rb — no offences.

🤖 Generated with Claude Code

Closes #9.

The existing tests only exercised the Aircraft model and missed several
behaviours that matter for downstream consumers (autocomplete, the query
translator's field validation). Tests pass on develop, so this fills the
coverage gaps left after the original failures were resolved across PR #13
review rounds and follow-up fixes.

Adds:
- Cross-model coverage for every SEARCHABLE_MODEL with an explicit
  expectation hash (Operator, AircraftType, Airport, Country,
  Manufacturer, Route), so a regression in any model's
  filterable_attributes surfaces here rather than downstream.
- Assertion that fields_for returns Symbols (the registry's contract;
  meilisearch_attribute_for relies on `.to_sym` round-trips).
- A test for the rescue StandardError branch via a temporary
  singleton-method swap. Ensures the registry stays defensive against
  per-model indexing misconfiguration.
- Symbol input to meilisearch_attribute_for (matches valid_field?'s
  existing dual-input coverage).
- suggest_fields sort order assertion (the method does an explicit
  sort_by; previously only presence was checked).
- suggest_fields :display humanisation (was completely untested).

6 new tests, 23 new assertions, no production code changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 28, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens coverage for the search field registry without changing production code, helping ensure model field metadata and autocomplete-related behavior remain stable.

Changes:

  • Adds cross-model assertions for expected filterable_attributes.
  • Adds coverage for Symbol field handling and rescued Meilisearch settings errors.
  • Adds assertions for sorted suggestions and humanized display labels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tardoe tardoe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kevinelliott kevinelliott merged commit be93082 into develop May 28, 2026
4 checks passed
@kevinelliott kevinelliott deleted the fix/field-registry-test-coverage branch May 28, 2026 10:36
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.

3 participants