Right, but even so, it should fail. When I try pasting my Apartment model into a fresh Rails app, it does:
ruby-1.9.2-p180 :001 > a = Apartment.new(:price => "G@I$G@GR #&GUGshkj4h53$$$*@^") => #<Apartment _id: 4e1d74fa35be3560e8000001, _type: nil, created_at: nil, updated_at: nil,price: "G@I$G@GR#&GUGshkj4h53$$$*@^"> ruby-1.9.2-p180 :002 > a.valid? => *false* I compared the Gemfiles of both apps, and they're identical.... This is very strange... On Wed, Jul 13, 2011 at 1:32 PM, Bernd Ritter <com...@gmail.com> wrote: > Hi Avishai, > > i just tried this: > > irb(main):001:0> "G@I$G@GR#&GUGshkj4h53$$$*@^".to_i > => 0 > > As I don't know how the conversion would work, but if it works like that it > will return 0. But it still should not be valid.Hmmm. > > Bernd > > 2011/7/13 Avishai Weiss <avishai.we...@gmail.com> > >> Yes, the price is random junk that's clearly supposed to fail validation, >> but it passes with no errors. >> >> I just tried it with the validations after the field definitions; still >> the same problem. >> >> Cheers, >> >> Avishai >> >> On Wed, Jul 13, 2011 at 12:42 PM, Bernd Ritter <com...@gmail.com> wrote: >> >>> Hi, >>> >>> that price looks like random stuff. Is it relevant that you call the >>> validator before the field-definition? >>> >>> Greetings, >>> Bernd >>> >>> >>> 2011/7/13 Avishai <avishai.we...@gmail.com> >>> >>>> 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 >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msg/rubyonrails-talk/-/u8C4AV2SfNQJ. >>>> To post to this group, send email to rubyonrails-talk@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> rubyonrails-talk+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk@googlegroups.com. >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.