Skip to content

Add safe navigation to file_formats method#969

Open
jazairi wants to merge 1 commit into
mainfrom
use-628
Open

Add safe navigation to file_formats method#969
jazairi wants to merge 1 commit into
mainfrom
use-628

Conversation

@jazairi

@jazairi jazairi commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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):

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.

Developer

  • All new ENV is documented in README
  • All new ENV has been added to Heroku Pipeline, Staging and Prod
  • ANDI or Wave has been run in accordance to
    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)
  • Stakeholder approval has been confirmed (or is not needed)

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • There are appropriate tests covering any new functionality
  • The documentation has been updated or is unnecessary
  • The changes have been verified
  • New dependencies are appropriate or there were no changes

Requires database migrations?

NO

Includes new or updated dependencies?

NO

@qltysh

qltysh Bot commented Jun 15, 2026

Copy link
Copy Markdown

All good ✅

Comment thread test/graphql/types/record_type_test.rb
Comment thread test/graphql/types/record_type_test.rb Outdated
Comment thread test/graphql/types/record_type_test.rb Outdated
Comment thread test/graphql/types/record_type_test.rb Outdated
Comment thread test/graphql/types/record_type_test.rb Outdated
@mitlib mitlib temporarily deployed to timdex-api-p-use-628-hurm5l0lw June 15, 2026 17:10 Inactive

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 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_formats to use &.uniq instead of calling uniq on a potentially-nil value.
  • Add unit tests for file_formats when 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.

Comment thread test/graphql/types/record_type_test.rb Outdated
Comment thread test/graphql/types/record_type_test.rb Outdated
Comment thread test/graphql/types/record_type_test.rb Outdated
@jazairi jazairi temporarily deployed to timdex-api-p-use-628-hurm5l0lw June 15, 2026 18:26 Inactive
@jazairi jazairi requested a review from Copilot June 15, 2026 18:35
@jazairi jazairi temporarily deployed to timdex-api-p-use-628-hurm5l0lw June 15, 2026 18:35 Inactive

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread test/graphql/types/record_type_test.rb Outdated
@jazairi jazairi temporarily deployed to timdex-api-p-use-628-hurm5l0lw June 15, 2026 19:12 Inactive
@jazairi jazairi requested a review from Copilot June 15, 2026 19:24

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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.
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.

5 participants