Bug #34141
validate_presence and validate_readable with predicate broken
Pull request:
Fixed in Releases:
Found in Releases:
Description
When using the following code in modern Ruby, it starts to fail:
validate_presence :setting, if: ->(settings) { false }
This causes the if: part to be interpreted as a setting to validate, rather than as a predicate for :setting.
I reproduced this on Smart Proxy 3.2.0-develop with Ruby 3. It looks like there's no test coverage for this use case.
Associated revisions
History
#1
Updated by The Foreman Bot 5 months ago
- Assignee set to Ewoud Kohl van Wijngaarden
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/smart-proxy/pull/806 added
#2
Updated by The Foreman Bot 4 months ago
- Fixed in Releases 3.2.0 added
#3
Updated by Ewoud Kohl van Wijngaarden 4 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset 01b39acde45a27d0b25912c2e0d449f772a59745.
Fixes #34141 - Make validators modern Ruby compatible
In old Ruby versions a hash was pushed as the last argument but in
modern Ruby there is first class support for this via kwargs. This
worked if a single argument was provided but if they were combined it
failed:
This then tried to create a validator of a hash rather than as a
predicate. It then also unconditionally validates :setting.