Skip to content

Add ActiveModel::Attributes model-reader tests + CHANGELOG for Type#cast - #3

Merged
HoneyryderChuck merged 1 commit into
persona-id:fix-type-castfrom
rastamhadi:add-activemodel-cast-tests
Jul 16, 2026
Merged

Add ActiveModel::Attributes model-reader tests + CHANGELOG for Type#cast#3
HoneyryderChuck merged 1 commit into
persona-id:fix-type-castfrom
rastamhadi:add-activemodel-cast-tests

Conversation

@rastamhadi

@rastamhadi rastamhadi commented Jul 14, 2026

Copy link
Copy Markdown

Stacked on top of brainspec#476. Test and CHANGELOG coverage only — no change to the #cast implementation from that PR.

What's here

  • CHANGELOG entry for the #cast fix.
  • Model-level regression tests that drive the enumerized reader through a new CastActiveModelUser fixture, covering: predicate after assignment, wrapping an after-init assignment, the wrapped default, nil handling, invalid-value validation, and multiple: true staying an Enumerize::Set.

Why these tests

The existing Type#cast specs assert the type in isolation (type.cast(...)), which passes regardless of the ancestor-chain ordering that actually regressed on Rails 8.1. The new fixture reproduces the exposed path — the code comments on CastActiveModelUser and the describe 'Type#cast (model reader)' block explain the ordering mechanism and exactly which examples fail without the #cast override.

Validation

Green on Rails 8.1.3, 8.0.5, and 7.2.3.1 (Ruby 3.3.6): 33 runs, 60 assertions, 0 failures.

Root-cause write-up: brainspec#482. Related Rails-side report: rails/rails#53985.

The existing Type#cast specs assert the type in isolation. Add
model-level regression coverage using a model whose enumerize
attributes are declared without a preceding plain `attribute`, so on
Rails 8.1 the generated reader outranks enumerize's module and reads
resolve through #cast. Without the #cast override these fail with a
raw String/Symbol; value predicates then raise NoMethodError.

Also add a CHANGELOG entry for the #cast fix. Verified on Rails
8.1.3, 8.0.5 and 7.2.3.1 (Ruby 3.3.6).

Refs brainspec#482

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants