Fix Type#cast to support Rails 8.0 bulk operations#469
Merged
nashby merged 2 commits intobrainspec:masterfrom Sep 10, 2025
Merged
Fix Type#cast to support Rails 8.0 bulk operations#469nashby merged 2 commits intobrainspec:masterfrom
nashby merged 2 commits intobrainspec:masterfrom
Conversation
- Test Type#cast returns Enumerize::Value for symbols, integers, and strings - Test Type#cast handles invalid values and preserves existing Value objects - Test insert_all/upsert_all work with mixed value types and handle invalid values
…rations Rails 8.0 changed how Type#cast is used during insert_all/upsert_all operations, causing symbol enum values (e.g., :active) to fail. The previous implementation always delegated to @subtype.cast first, which could incorrectly transform symbol values before looking them up. This fix: - First attempts to find the enumerize value directly with the input value - Only delegates to @subtype.cast if the direct lookup fails - Ensures both symbol values (:active) and their database representations (1) work correctly This maintains backward compatibility while fixing bulk operations in Rails 8.0.
Member
|
@snaka thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
To run tests on this PR, it is necessary to merge the following PRs first
Motivation / Background
This Pull Request has been created because Rails 8.0 introduced changes to how
Type#castis used during bulk operations (insert_all,upsert_all), causing enumerated attributes with symbol values to fail. The issue affects only bulk operations while regular attribute assignment continues to work correctly.Fixes #462
Detail
This Pull Request changes the
Type#castmethod in enumerize to handle values more intelligently for Rails 8.0 compatibility.Steps to reproduce
Expected behavior
Bulk operations (
insert_all,upsert_all) should work correctly with symbol enum values like:active, just like regular attribute assignment does.Actual behavior
In Rails 8.0, bulk operations fail when using symbol enum values because the
Type#castmethod incorrectly delegates to@subtype.castfirst, which returnsnilfor symbols when the subtype is an integer type.System configuration
Rails version: 8.0
Ruby version: 3.1.6
Testing
Added comprehensive tests for:
Type#castbehavior with symbols, strings, and integersinsert_allwith mixed value typesupsert_allwith different value formatsEnumerize::ValueobjectsAll tests pass on Rails 7.0, 7.1, and 8.0.