Skip to content
This repository

validates_numericality_of does not work properly for BigDecimal #1943

raphaelcm opened this Issue April 23, 2012 · 1 comment

3 participants

Raphael Crawford-Marks Durran Jordan Nick Hoffman
Raphael Crawford-Marks

Mongoid (2.2) validates_numericality_of validator does not work for BigDecimal fields:

class TestModel
  include Mongoid::Document

  field :amount, :type => BigDecimal

  validates_numericality_of :amount, :allow_blank => false
ree-1.8.7-2011.03 :009 > a =
 => #<TestModel _id: 4f95a22fe628f831c9000003, amount: nil, _type: nil> 
ree-1.8.7-2011.03 :010 > a.amount = "asdf"
 => "asdf" 
ree-1.8.7-2011.03 :011 > a.valid?
 => true 
ree-1.8.7-2011.03 :012 > a.errors
 => #<OrderedHash {}>

If I change the field type to Integer, then it works properly:

ree-1.8.7-2011.03 :015 > a =
 => #<TestModel _id: 4f95a277e628f831c9000005, amount: nil, _type: nil> 
ree-1.8.7-2011.03 :016 > a.amount = "Asdf"
 => "Asdf" 
ree-1.8.7-2011.03 :017 > a.valid?
 => false 
ree-1.8.7-2011.03 :018 > a.errors
 => #<OrderedHash {:amount=>["is not a number"]}>
Nick Hoffman

Thanks for reporting this, @raphaelcm. It's been marked for v2.4.9 .

Durran Jordan durran closed this in b303acb April 24, 2012
Vince Puzzella vpuzzella referenced this issue from a commit September 05, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.