GrapeSwagger::DocMethods::Extensions breaks the contract of Kernel#method (#760)

* GrapeSwagger::DocMethods::Extensions breaks the contract of

Kernel#method

This causes code inspection tools and development workflows to break
and may cause developers to choose not to use the gem.

* add test for method introspection on GrapeSwagger::DocMethods::Extensions

* fix ci lint failure
This commit is contained in:
Tim Galeckas 2019-10-03 03:47:16 -05:00 committed by peter scholz
parent d7bf077802
commit 3de44a3a6f
3 changed files with 19 additions and 2 deletions

View File

@ -87,7 +87,12 @@ module GrapeSwagger
part.select { |x| x == identifier } part.select { |x| x == identifier }
end end
def method def method(*args)
# We're shadowing Object.method(:symbol) here so we provide
# a compatibility layer for code that introspects the methods
# of this class
return super if args.size.positive?
@route.request_method.downcase.to_sym @route.request_method.downcase.to_sym
end end
end end

View File

@ -3,6 +3,16 @@
require 'spec_helper' require 'spec_helper'
describe GrapeSwagger::DocMethods::Extensions do describe GrapeSwagger::DocMethods::Extensions do
context 'it should not break method introspection' do
describe '.method' do
describe 'method introspection' do
specify do
expect(described_class.method(described_class.methods.first)).to be_a(Method)
end
end
end
end
describe '#find_definition' do describe '#find_definition' do
subject { described_class } subject { described_class }

View File

@ -10,7 +10,9 @@ describe 'document hash and array' do
class TestApi < Grape::API class TestApi < Grape::API
format :json format :json
documentation = ::Entities::DocumentedHashAndArrayModel.documentation if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation) if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation)
documentation = ::Entities::DocumentedHashAndArrayModel.documentation
end
desc 'This returns something' desc 'This returns something'
namespace :arbitrary do namespace :arbitrary do