-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5843 Ensure BSON::Decimal128 is considered to be numeric #5961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR updates Mongoid’s numericality validation to recognize BSON::Decimal128 as a numeric value by converting it to BigDecimal before validation.
- Adds a new NumericalityValidator subclass that handles BSON::Decimal128.
- Updates the macros to include a validates_numericality_of helper.
- Includes additional tests to verify that both string and BSON::Decimal128 inputs validate correctly.
Reviewed Changes
| File | Description |
|---|---|
| lib/mongoid/validatable/numericality.rb | Implements the specialized validator for BSON::Decimal128 conversion. |
| spec/mongoid/validatable/numericality_spec.rb | Adds tests for numeric and BSON::Decimal128 values to ensure proper validation. |
| lib/mongoid/validatable/macros.rb | Provides the validates_numericality_of method to enable the new validator. |
| lib/mongoid/validatable.rb | Adds a require statement for the new numericality validator module. |
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
This reverts commit 243fc49.
concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
comandeo-mongo
approved these changes
Mar 11, 2025
jamis
added a commit
to jamis/mongoid
that referenced
this pull request
Mar 11, 2025
…godb#5961) * RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric * bump drivers-evergreen-tools * let's see how this version of drivers-evergreen-tools does * Revert "let's see how this version of drivers-evergreen-tools does" This reverts commit 243fc49. * don't try to run `rails new` on rails < 7.1 concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
jamis
added a commit
to jamis/mongoid
that referenced
this pull request
Mar 11, 2025
…godb#5961) * RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric * bump drivers-evergreen-tools * let's see how this version of drivers-evergreen-tools does * Revert "let's see how this version of drivers-evergreen-tools does" This reverts commit 243fc49. * don't try to run `rails new` on rails < 7.1 concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
jamis
added a commit
to jamis/mongoid
that referenced
this pull request
Mar 11, 2025
…godb#5961) * RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric * bump drivers-evergreen-tools * let's see how this version of drivers-evergreen-tools does * Revert "let's see how this version of drivers-evergreen-tools does" This reverts commit 243fc49. * don't try to run `rails new` on rails < 7.1 concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
jamis
added a commit
that referenced
this pull request
Mar 13, 2025
…) (#5964) * RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric * bump drivers-evergreen-tools * let's see how this version of drivers-evergreen-tools does * Revert "let's see how this version of drivers-evergreen-tools does" This reverts commit 243fc49. * don't try to run `rails new` on rails < 7.1 concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
jamis
added a commit
that referenced
this pull request
Mar 13, 2025
…) (#5965) * RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric * bump drivers-evergreen-tools * let's see how this version of drivers-evergreen-tools does * Revert "let's see how this version of drivers-evergreen-tools does" This reverts commit 243fc49. * don't try to run `rails new` on rails < 7.1 concurrent-ruby gem removed a dependency on logger, which rails assumed was there. Installing those versions of Rails will install a too-new version of concurrent-ruby, which causes `rails new` to fail because it can't resolve Logger.
Closed
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.
Because ActiveModel's
validate_numericality_ofvalidator looks at the value of a field before it was typecast, it fails when the underlying type is aBSON::Decimal128(which is not a true numeric type). This PR specializes ActiveModel'sNumericalityValidatorso that it recognizesBSON::Decimal128as a numeric type.