Skip to content

Commit

Permalink
fix a breaking change provided in 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dm1try committed Feb 19, 2022
1 parent e93d278 commit 9687a88
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
* [#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).
* [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename "MissingGroupType" and "UnsupportedGroupType" exceptions - [@ericproulx](https://github.com/ericproulx).
* [#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).
* Your contribution here.

### 1.6.2 (2021/12/30)
Expand Down
1 change: 1 addition & 0 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ module Validations
autoload :Types
autoload :ParamsScope
autoload :ValidatorFactory
autoload :Base, 'grape/validations/validators/base'
end

module Types
Expand Down
7 changes: 7 additions & 0 deletions lib/grape/validations/validators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions spec/grape/api/custom_validations_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9687a88

Please sign in to comment.