test(search): strengthen FieldRegistry coverage (closes #9)#17
Merged
Conversation
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>
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 acrosse48a97b("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.fields_forexpectationsSEARCHABLE_MODEL(Operator, AircraftType, Airport, Country, Manufacturer, Route) returns its declaredfilterable_attributes. A single hash assertion so regressions surface here, not in downstream search tests.fields_forreturns Symbolsmeilisearch_attribute_forrelies onto_symround-trips.fields_forrescues StandardErrorObject#stub; anensureblock restores the original).meilisearch_attribute_foraccepts Symbol inputvalid_field?already had.suggest_fieldssort order:value; previously only presence was checked.suggest_fields:displayhumanisationhumanize_field_namecallstitleize; 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