codegram / date_validator

A simple, ORM agnostic, Ruby >=2.2 compatible date validator for Rails, based on ActiveModel.
http://thoughts.codegram.com/date-validation-with-rails-3
MIT License
495 stars 82 forks source link

Skip { after: :other_attribute } validation if other_attribute is nil #87

Open slucaskim opened 3 years ago

slucaskim commented 3 years ago

🦄 Feature Request

Is your feature request related to a problem?

When I'm using the after syntax using an attribute:

validates :expiration_date, date: { after: :packaging_date }

but then packaging_date is a nilable attribute, the validation fails when packaging_date is blank.

Describe the solution you'd like

The more sensible behaviour to me is if the after validation is only applied in case where packaging_date is present. If packaging_date is blank, the date validation should just check the date format of expiration_date. If this makes sense with the authors and the users, I'm totally willing to put in a PR!

Ceda commented 3 years ago

next if option_value.blank? to > https://github.com/codegram/date_validator/blob/master/lib/active_model/validations/date_validator.rb#L84