Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a breaking change provided in 1.6.1 #2244

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a PR for adding a warn message to MissingGroupType and UnsupportedGroupType

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