From 6e12833643b7bf0537141d95940d95de52e27e5b Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sat, 26 Oct 2024 14:04:28 +0200 Subject: [PATCH] Renamed ValidatorsCache to ValidatorsRegistry --- lib/grape/validations.rb | 4 ++-- spec/grape/validations_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/grape/validations.rb b/lib/grape/validations.rb index 5d5408218d..5df7b2f3be 100644 --- a/lib/grape/validations.rb +++ b/lib/grape/validations.rb @@ -5,12 +5,12 @@ module Validations module_function def require_validator(short_name) - ValidatorsCache[short_name] + ValidatorsRegistry[short_name] rescue NameError raise Grape::Exceptions::UnknownValidator, short_name end - class ValidatorsCache < Grape::Util::Cache + class ValidatorsRegistry < Grape::Util::Cache def initialize super @cache = Hash.new do |h, name| diff --git a/spec/grape/validations_spec.rb b/spec/grape/validations_spec.rb index 19dd130f03..47acd13955 100644 --- a/spec/grape/validations_spec.rb +++ b/spec/grape/validations_spec.rb @@ -2026,5 +2026,21 @@ def validate_param!(attr_name, params) expect { subject }.to raise_error(Grape::Exceptions::UnknownValidator) end end + + context 'when custom' do + let(:short_name) { :custom } + let(:custom_validator) do + Class.new(Grape::Validations::Validators::Base) do + def validate_param!(_attr_name, _params) + end + end + end + + before do + stub_const('Grape::Validations::Validators::CustomValidator', custom_validator) + end + + it { is_expected.to be(Grape::Validations::Validators::CustomValidator) } + end end end