Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2137

validates_numericality does not work for integer

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      I am using a Numericality Validator on an Integer field. But the validator does not work as expected, I am able to save a String. In this case it will be typecasted to 0.

      class Log
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :user_id,     type: Integer
        field :user_agent,  type: String
        field :url,         type: String
        
        validates_numericality_of :user_id, :only_integer => true
      end
      
      @log.user_id = 'abc'
      @log.valid? # true
      @log.user_id == 0 # true
      

      I am using Mongoid 3.0.0.rc.

      Maybe this issue relates to MONGOID-1736 ?

            Assignee:
            Unassigned Unassigned
            Reporter:
            MMore MMore [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: