Hi,
I’m having some serious problems with my validations. I have a mongoid model set up with validations, which looks like this:
class Apartment
include Mongoid::Document
include Mongoid::Timestamps
validates :price, :numericality => { :greater_than => 0, :allow_blank => false }
field :price, :type => Integer end
But then when I actually try to run the validations, they pass and claim the object is valid, even if I pass complete garbage. Here’s the output:
ruby-1.9.2-p180 :006 > Apartment.validators_on(:price)
=> [#<ActiveModel::Validations::NumericalityValidator:0x00000102924cc8 @attributes=[:price], @options={:only_integer=>false, :allow_nil=>false, :greater_than=>0, :allow_blank=>false}>]
ruby-1.9.2-p180 :007 > a = Apartment.new(:price => “G@I$G@GR#&GUGshkj4h53$$$*@^”)
=> #<Apartment _id: 4e1d66f835be35fddb000002, _type: nil, created_at: nil, updated_at: nil, address: nil, price: “G@I$G@GR#&GUGshkj4h53$$$*@^”>
ruby-1.9.2-p180 :008 > a.valid?
=> true
I’ve tried disabling gems, commenting out and then re-adding validations one by one, but nothing seems to work. If you have any fresh direction on how to track this down, I’d really appreciate it. Thanks!
-Avishai