gregnavis / active_record_doctor

Identify database issues before they hit production.
MIT License
1.72k stars 56 forks source link

MissingPresenceValidation should ignore enum's with default values #154

Closed fidalgo closed 9 months ago

fidalgo commented 10 months ago

If you have a model, where an enum is defined with a default (or _default_ keyword) like this:


class Profile < ApplicationRecord
    enum kind: {general: 0, admin: 1}, _default: :general
end

The report should not include a missing presence validator for the field.
gregnavis commented 9 months ago

This doesn't sound like a bug as a default value doesn't prevent the color from creating a model with an explicit nil value. For example:

Profile.create!(kind: nil)

I think in this case active_record_doctor discovered an actual bug or edge case in your code. I recommend that you ignore that warning via configuration or add a strict validator.