Revision 01b39acd
Added by Ewoud Kohl van Wijngaarden over 2 years ago
test/plugins/module_loader_test.rb | ||
---|---|---|
assert results.include?(:class => ::Proxy::PluginValidators::Presence, :setting => :default_2, :args => nil, :predicate => nil)
|
||
end
|
||
|
||
VALIDATOR_PREDICATE = ->(settings) { false }
|
||
class TestPluginWithBuiltInValidators < ::Proxy::Plugin
|
||
default_settings :default_1 => "one", :default_2 => "two"
|
||
validate_presence :missing_setting, if: VALIDATOR_PREDICATE
|
||
validate_readable :missing_path, if: VALIDATOR_PREDICATE
|
||
end
|
||
def test_presence_validator_called_with_predicate
|
||
loader = ::Proxy::DefaultModuleLoader.new(TestPluginWithBuiltInValidators, nil)
|
||
results = loader.validate_settings(TestPluginWithBuiltInValidators, :default_1 => "one", :default_2 => "two")
|
||
assert_includes results, {:class => ::Proxy::PluginValidators::Presence, :setting => :default_1, :args => nil, :predicate => nil}
|
||
assert_includes results, {:class => ::Proxy::PluginValidators::Presence, :setting => :default_2, :args => nil, :predicate => nil}
|
||
assert_includes results, {:class => ::Proxy::PluginValidators::Presence, :setting => :missing_setting, :args => true, :predicate => VALIDATOR_PREDICATE}
|
||
assert_includes results, {:class => ::Proxy::PluginValidators::FileReadable, :setting => :missing_path, :args => true, :predicate => VALIDATOR_PREDICATE}
|
||
end
|
||
|
||
class TestValidator < ::Proxy::PluginValidators::Base
|
||
def validate!(settings)
|
||
true
|
Also available in: Unified diff
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.