-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check conditions for presence validators to see if an attribute is required #693
Conversation
Merging this since |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Travis days, failures on edge weren't blocking failures. Maybe we have to look into that.
Thanks for jumping on this so quickly!
if_option = validator.options[:if] | ||
unless_opt = validator.options[:unless] | ||
(!if_option || call_with_self(object, if_option)) && (!unless_opt || !call_with_self(object, unless_opt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we now handle conditional validators, right?
validator_class == ActiveModel::Validations::PresenceValidator || | ||
(defined?(ActiveRecord::Validations::PresenceValidator) && | ||
target_validators.include?(ActiveRecord::Validations::PresenceValidator)) | ||
validator_class == ActiveRecord::Validations::PresenceValidator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never understood why the second part of the || is going to make a difference.
if required | ||
option[:required] = true | ||
option[:aria] ||= {} | ||
option[:aria][:required] = true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Fixes #691