Merge pull request #1670 from duduribeiro/fix_positional_arguments_in_ruby_3
Fix usage of inherited Sinatra::Base classes keyword arguments
This commit is contained in:
commit
d39b135c67
|
@ -916,7 +916,7 @@ module Sinatra
|
|||
attr_accessor :app, :env, :request, :response, :params
|
||||
attr_reader :template_cache
|
||||
|
||||
def initialize(app = nil)
|
||||
def initialize(app = nil, **kwargs)
|
||||
super()
|
||||
@app = app
|
||||
@template_cache = Tilt::Cache.new
|
||||
|
@ -1522,8 +1522,8 @@ module Sinatra
|
|||
# Create a new instance of the class fronted by its middleware
|
||||
# pipeline. The object is guaranteed to respond to #call but may not be
|
||||
# an instance of the class new was called on.
|
||||
def new(*args, &bk)
|
||||
instance = new!(*args, &bk)
|
||||
def new(*args, **kwargs, &bk)
|
||||
instance = new!(*args, **kwargs, &bk)
|
||||
Wrapper.new(build(instance).to_app, instance)
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@ class BaseTest < Minitest::Test
|
|||
get('/') { 'Hello World' }
|
||||
end
|
||||
|
||||
class TestKeywordArgumentInitializerApp < Sinatra::Base
|
||||
def initialize(argument:)
|
||||
@argument = argument
|
||||
end
|
||||
|
||||
get('/') { "Hello World with Keyword Arguments: #{@argument}" }
|
||||
end
|
||||
|
||||
it 'include Rack::Utils' do
|
||||
assert TestApp.included_modules.include?(Rack::Utils)
|
||||
end
|
||||
|
@ -48,6 +56,16 @@ class BaseTest < Minitest::Test
|
|||
TestApp.configure { context = self }
|
||||
assert_equal self, context
|
||||
end
|
||||
|
||||
it "allows constructor to receive keyword arguments" do
|
||||
app = TestKeywordArgumentInitializerApp.new(argument: "some argument")
|
||||
request = Rack::MockRequest.new(app)
|
||||
|
||||
response = request.get('/')
|
||||
|
||||
assert response.ok?
|
||||
assert_equal 'Hello World with Keyword Arguments: some argument', response.body
|
||||
end
|
||||
end
|
||||
|
||||
describe "Sinatra::Base#new" do
|
||||
|
|
Loading…
Reference in New Issue