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

numericality validation not working (due to missing `attribute_before_type_cast`)

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

      Basically the type coercion on assignment is causing items that should not be valid to appear valid

      class Company
        include Mongoid::Document
        field :revenue, type: Float
        validates_numericality_of :revenue
      end
      
      company = Company.new revenue: 'one million dollars'
      company.valid? # => true
      

      The company is showing up as valid even though it is not, due to the model not responding to company.revenue_before_type_cast and the type cast on assignment forcing the string to 0.

            Assignee:
            Unassigned Unassigned
            Reporter:
            gerad Gerad Suyderhoud
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: