Skip to content

Add test coverage for the remaining Type::Date cast branches - #57643

Merged
byroot merged 1 commit into
rails:mainfrom
hammadxcm:test-type-date-cast-branches
Jun 10, 2026
Merged

byroot merged 1 commit into
rails:mainfrom
hammadxcm:test-type-date-cast-branches

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

ActiveModel::Type::Date#cast was only tested for nil/blank/unparseable strings, ISO-format strings, and multiparameter hashes. This completes coverage of the remaining distinct branches of cast_value (each a separate code path, not a new input to an already-tested case). Test-only; no production changes.

  • a value responding to #to_date (e.g. a Time or Date) is cast via #to_date — the documented "Any other values are cast using their to_date method" behavior
  • a non-ISO but parseable string goes through the fallback parser (fallback_string_to_date), distinct from the ISO_DATE fast path
  • a well-formed but calendar-invalid date string ("2008-02-31") returns nil via the Date.new ... rescue nil guard — distinct from the unparseable "ABC" case, which is caught earlier by the nil-parts guard
  • a value that is neither a String nor responds to #to_date is returned unchanged (the else branch)

Type::Date#cast only had coverage for nil/blank/unparseable strings,
ISO-format strings, and multiparameter hashes. Cover the remaining
distinct casting branches:

- a value responding to #to_date (Time, Date) is cast via #to_date
- a non-ISO but parseable string is parsed by the fallback parser
- a well-formed but calendar-invalid date string returns nil
- a value that is neither a String nor responds to #to_date is returned
  unchanged
@byroot
byroot merged commit 39c28dc into rails:main Jun 10, 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