Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents RecordType#file_formats from raising when the underlying file_formats field is missing/nil by using safe navigation, and adds a regression test to cover the nil case.
Changes:
- Update
RecordType#file_formatsto use&.uniqinstead of callinguniqon a potentially-nil value. - Add unit tests for
file_formatswhen missing/nil and when populated (deduplication behavior).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| app/graphql/types/record_type.rb | Makes file_formats nil-safe by using safe navigation before uniq. |
| test/graphql/types/record_type_test.rb | Adds regression coverage for nil/missing file_formats and verifies deduplication behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Why these changes are being introduced: We are calling `uniq` on `file_formats`, which returns a nil error if that field does not exist. Relevant ticket(s): - [TIMX-628](https://mitlibraries.atlassian.net/browse/TIMX-628) How this addresses that need: This adds a safe navigation operator to the `file_formats` method. Side effects of this change: I added a regression test, which creates a new test file. It feels a bit odd not to test the other Record Type methods in there, but doing so seemed far out of scope of this ticket.
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.
Why these changes are being introduced:
We are calling
uniqonfile_formats, whichreturns a nil error if that field does not exist.
Relevant ticket(s):
How this addresses that need:
This adds a safe navigation operator to the
file_formatsmethod.Side effects of this change:
I added a regression test, which creates a new
test file. It feels a bit odd not to test the
other Record Type methods in there, but doing so
seemed far out of scope of this ticket.
Developer
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Code Reviewer
(not just this pull request message)
Requires database migrations?
NO
Includes new or updated dependencies?
NO