Skip to content

Add test coverage for Enumerable key-helper edge cases - #57572

Merged
rafaelfranca merged 1 commit into
rails:mainfrom
hammadxcm:test-enumerable-key-helpers-edge-cases
Jun 4, 2026
Merged

rafaelfranca merged 1 commit into
rails:mainfrom
hammadxcm:test-enumerable-key-helpers-edge-cases

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

Adds coverage for several untested edge cases of the Enumerable key-extraction and blank-filtering helpers in active_support/core_ext/enumerable.rb. All test-only; no production code changes.

  • pluck with a single key missing from some elements yields nil in its place
  • pluck with multiple keys, one missing from an element, yields nil inside the tuple
  • pick with keys missing from the first element yields nil (single key) or nil within the array (multiple keys)
  • compact_blank on a Set returns an Array — the behavior shown in the method's documentation

The existing pluck/pick tests only used keys present on every element, and compact_blank was only tested on a generic enumerable, so these cases were unexercised.

Cover untested edge cases of the Enumerable key-extraction and
blank-filtering helpers in active_support/core_ext/enumerable.rb:

- pluck with a single key missing from some elements yields nil
- pluck with multiple keys missing from some elements yields nil in the tuple
- pick with keys missing from the first element yields nil
- compact_blank on a Set returns an Array (as documented)
@rafaelfranca
rafaelfranca merged commit 7c31215 into rails:main Jun 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants