Skip to content

Add test coverage for ActiveSupport::Duration edge cases - #57658

Merged
byroot merged 1 commit into
rails:mainfrom
hammadxcm:test-duration-branch-coverage
Jun 11, 2026
Merged

byroot merged 1 commit into
rails:mainfrom
hammadxcm:test-duration-branch-coverage

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

Adds coverage for several untested branches and documented behaviors of ActiveSupport::Duration. Each is a distinct code path (or a behavior shown in the method's own docs) with no conceptually-equivalent existing test. Test-only; no production changes.

  • -@ (unary minus) negates the value and every entry in parts (existing tests only cover +@)
  • .build decomposes a number of seconds into the parts shown in its rdoc (e.g. build(2716146).parts # => { months: 1, days: 1 }); existing .build tests only cover error cases and the resulting time
  • #parts returns an independent copy — mutating the result leaves the duration unchanged
  • #<=> returns nil for an object that is neither a Duration nor Numeric (only Scalar#<=>'s nil path was tested)
  • #coerce with a Duration argument wraps the other value in a Scalar (only Scalar#coerce was tested)

Cover several untested branches and documented behaviors of
ActiveSupport::Duration:

- unary minus negates the value and every part
- .build decomposes a number of seconds into the parts shown in its
  documentation
- #parts returns an independent copy, leaving the duration unchanged
  when the result is mutated
- #<=> returns nil for an object that is neither a Duration nor Numeric
- #coerce with a Duration wraps the other value in a Scalar
@byroot
byroot merged commit f6c8492 into rails:main Jun 11, 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