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

validates_inclusion_of does not consider the coerced value

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

      The validates_inclusion_of is not using the coerced value. Is this intentional? Here is an example:

      
      require 'mongoid'
      
      class Book
        include Mongoid::Document
        field :genre, type: Symbol
        validates_inclusion_of :genre, in: [:drama, :adventure]
      end
      
      b = Book.new
      
      b.genre = :drama
      b.valid? # true
      
      b.genre = 'drama'
      b.valid? # false
      

      Mongoid used to return true for the second case too. This code was tested in the newest gem version (currently 3.1.0), but I don't know exactly when this was changed.

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            lailsonbm lailsonbm
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: