Skip to content

Commit cf1e4e5

Browse files
authored
Merge pull request #2244 from dm1try/fix_breaking_change
fix a breaking change provided in 1.6.1
2 parents e93d278 + 9687a88 commit cf1e4e5

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
1414
* [#2234](https://github.com/ruby-grape/grape/pull/2234): Remove non-utf-8 characters from format before generating JSON error - [@bschmeck](https://github.com/bschmeck).
1515
* [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename "MissingGroupType" and "UnsupportedGroupType" exceptions - [@ericproulx](https://github.com/ericproulx).
16+
* [#2244](https://github.com/ruby-grape/grape/pull/2244): Fix a breaking change in `Grape::Validations` provided in 1.6.1 - [@dm1try](https://github.com/dm1try).
1617
* Your contribution here.
1718

1819
### 1.6.2 (2021/12/30)

lib/grape.rb

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 41 additions & 0 deletions
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)