Skip to content

Use is_a?(Enumerable) instead of respond_to?(:size) to detect collections#76

Merged
stas merged 7 commits intostas:masterfrom
dmolesUC:issue-75
Mar 21, 2022
Merged

Use is_a?(Enumerable) instead of respond_to?(:size) to detect collections#76
stas merged 7 commits intostas:masterfrom
dmolesUC:issue-75

Conversation

@dmolesUC
Copy link
Contributor

@dmolesUC dmolesUC commented Mar 15, 2022

What is the current behavior?

Non-collection objects with size attribute are mistakenly treated as collections, causing serialization to fail (see #75).

What is the new behavior?

Only Enumerables are treated as collections, cf. the corresponding method in jsonapi-serializer.

Fixes #75.

Checklist

Please make sure the following requirements are complete:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes /
    features)
  • All automated checks pass (CI/CD)

Notes

It looks like the build may be currently failing for other reasons?

@stas
Copy link
Owner

stas commented Mar 15, 2022

@dmolesUC any reason we don't want to switch to directly call JSONAPI::Serializer.is_collection? ?

@stas
Copy link
Owner

stas commented Mar 15, 2022

Ah, nvm, just saw you answered in the issue. I'll merge this and fix the CI. Sorry about that.

@dmolesUC
Copy link
Contributor Author

dmolesUC commented Mar 16, 2022

@stas It looks like the build is failing due to an unrelated RuboCop failure. Oops, never mind — I see you saw that.

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.

JSONAPI::Rails.is_collection? confused by 'size' attribute

2 participants