From c8436e7f2a1aa23f31fd84e1634cdca9a94e964a Mon Sep 17 00:00:00 2001 From: dm1try Date: Fri, 18 Feb 2022 02:24:50 +0300 Subject: [PATCH] fix a breaking change provided in 1.6.1 ref #2230 #2200 --- lib/grape.rb | 1 + lib/grape/validations/validators/base.rb | 7 ++++ spec/grape/api/custom_validations_spec.rb | 41 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/grape.rb b/lib/grape.rb index 7aedc07dba..57e1281f45 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -231,6 +231,7 @@ module Validations autoload :Types autoload :ParamsScope autoload :ValidatorFactory + autoload :Base, 'grape/validations/validators/base' end module Types diff --git a/lib/grape/validations/validators/base.rb b/lib/grape/validations/validators/base.rb index aaa06dc379..2c8403bbc5 100644 --- a/lib/grape/validations/validators/base.rb +++ b/lib/grape/validations/validators/base.rb @@ -93,3 +93,10 @@ def fail_fast? end end end + +Grape::Validations::Base = Class.new(Grape::Validations::Validators::Base) do + def initialize(*) + super + warn '[DEPRECATION] `Grape::Validations::Base` is deprecated. Use `Grape::Validations::Validators::Base` instead.' + end +end diff --git a/spec/grape/api/custom_validations_spec.rb b/spec/grape/api/custom_validations_spec.rb index 75c8b86417..25879fc57f 100644 --- a/spec/grape/api/custom_validations_spec.rb +++ b/spec/grape/api/custom_validations_spec.rb @@ -1,6 +1,47 @@ # frozen_string_literal: true describe Grape::Validations do + context 'deprecated Grape::Validations::Base' do + subject do + Class.new(Grape::API) do + params do + requires :text, validator_with_old_base: true + end + get do + end + end + end + + let(:validator_with_old_base) do + Class.new(Grape::Validations::Base) do + def validate_param!(_attr_name, _params) + true + end + end + end + + before do + described_class.register_validator('validator_with_old_base', validator_with_old_base) + allow(Warning).to receive(:warn) + end + + after do + described_class.deregister_validator('validator_with_old_base') + end + + def app + subject + end + + it 'puts a deprecation warning' do + expect(Warning).to receive(:warn) do |message| + expect(message).to include('`Grape::Validations::Base` is deprecated') + end + + get '/' + end + end + context 'using a custom length validator' do subject do Class.new(Grape::API) do