-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Using mongoid (3.0.1):
I have run into problems with the validator. Specifically, it will accept floats and even non-numbers for integer fields and the validation passes.
class MyTest include Mongoid::Document include Mongoid::Timestamps field :filesize, :type => Integer validates_numericality_of :filesize, :greater_than_or_equal_to => 0, :only_integer => true end
mt = MyTest.new mt.filesize = 5.9 mt.valid? # true mt.filesize == 5 #true
That shouldn't be valid, but it says it is and truncates it to 5.
There's also this issue:
mt = MyTest.new mt.filesize = 'horse' mt.valid? # true mt.filesize == 0 #true
This seems directly related to issue MONGOID-2137, which was closed. However, this is a relevant issue for us as it breaks the ActiveRecord validation API.