Project

General

Profile

Bug #34141

validate_presence and validate_readable with predicate broken

Added by Ewoud Kohl van Wijngaarden 5 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Category:
Plugins
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
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

Revision 01b39acd (diff)
Added by Ewoud Kohl van Wijngaarden 4 months ago

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:

validate_presence :setting, if: ->(settings) { false }

This then tried to create a validator of a hash rather than as a
predicate. It then also unconditionally validates :setting.

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

Also available in: Atom PDF