Skip to content

Conversation

jamis
Copy link
Contributor

@jamis jamis commented Mar 7, 2025

Because ActiveModel's validate_numericality_of validator looks at the value of a field before it was typecast, it fails when the underlying type is a BSON::Decimal128 (which is not a true numeric type). This PR specializes ActiveModel's NumericalityValidator so that it recognizes BSON::Decimal128 as a numeric type.

@jamis jamis requested a review from Copilot March 7, 2025 22:09
@jamis jamis changed the title RUBY-5843 Ensure BSON::Decimal128 is considered to be numeric MONGOID-5843 Ensure BSON::Decimal128 is considered to be numeric Mar 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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.

@jamis jamis requested a review from comandeo-mongo March 7, 2025 22:10
jamis added 4 commits March 7, 2025 15:31
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 jamis merged commit 1d364ee into mongodb:master Mar 11, 2025
67 checks passed
@jamis jamis deleted the mongoid-5843 branch March 11, 2025 14:46
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.
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Apr 10, 2025
@jamis jamis mentioned this pull request Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug, with no new features or broken compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants