-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
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 end
ree-1.8.7-2011.03 :009 > a = TestModel.new => #<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.new => #<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"]}>