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

validates_inclusion_of failing on fields with type == Symbol

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

      After updating from 3.0.15 to 3.1.0 I am now having validation issues when using Symbol fields. If you set a field to a string value then it gets properly converted to a symbol, however validation_inclusion_of fails.

      For example:

      class Example
      include Mongoid::Document
      field :name, type: Symbol
      validates_inclusion_of :name, in: [:foo]
      end

      example = Example.new

      1. this works
        example.name = :foo
        example.valid? # => true
      1. but this fails
        example.name = "foo"
        example.name == :foo #=> true - string properly gets auto-converted to a symbol
        example.valid? #=> false - string version seems to be getting compared on validation

            Assignee:
            Unassigned Unassigned
            Reporter:
            jhoffner Jake Hoffner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: