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 17, 2022
1 parent e93d278 commit c8436e7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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 c8436e7

Please sign in to comment.