Skip to content

Commit

Permalink
Renamed ValidatorsCache to ValidatorsRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Oct 26, 2024
1 parent 870dffb commit 6e12833
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/grape/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
16 changes: 16 additions & 0 deletions spec/grape/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6e12833

Please sign in to comment.