Skip to content

Commit c8436e7

Browse files
committed
fix a breaking change provided in 1.6.1
ref #2230 #2200
1 parent e93d278 commit c8436e7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/grape.rb

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ module Validations
231231
autoload :Types
232232
autoload :ParamsScope
233233
autoload :ValidatorFactory
234+
autoload :Base, 'grape/validations/validators/base'
234235
end
235236

236237
module Types

lib/grape/validations/validators/base.rb

+7
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ def fail_fast?
9393
end
9494
end
9595
end
96+
97+
Grape::Validations::Base = Class.new(Grape::Validations::Validators::Base) do
98+
def initialize(*)
99+
super
100+
warn '[DEPRECATION] `Grape::Validations::Base` is deprecated. Use `Grape::Validations::Validators::Base` instead.'
101+
end
102+
end

spec/grape/api/custom_validations_spec.rb

+41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
# frozen_string_literal: true
22

33
describe Grape::Validations do
4+
context 'deprecated Grape::Validations::Base' do
5+
subject do
6+
Class.new(Grape::API) do
7+
params do
8+
requires :text, validator_with_old_base: true
9+
end
10+
get do
11+
end
12+
end
13+
end
14+
15+
let(:validator_with_old_base) do
16+
Class.new(Grape::Validations::Base) do
17+
def validate_param!(_attr_name, _params)
18+
true
19+
end
20+
end
21+
end
22+
23+
before do
24+
described_class.register_validator('validator_with_old_base', validator_with_old_base)
25+
allow(Warning).to receive(:warn)
26+
end
27+
28+
after do
29+
described_class.deregister_validator('validator_with_old_base')
30+
end
31+
32+
def app
33+
subject
34+
end
35+
36+
it 'puts a deprecation warning' do
37+
expect(Warning).to receive(:warn) do |message|
38+
expect(message).to include('`Grape::Validations::Base` is deprecated')
39+
end
40+
41+
get '/'
42+
end
43+
end
44+
445
context 'using a custom length validator' do
546
subject do
647
Class.new(Grape::API) do

0 commit comments

Comments
 (0)