Pass the class to configure blocks
This allows for the following idiom in top-level apps: configure do |app| set :foo, app.root + '/foo' end
This commit is contained in:
parent
da8271f05b
commit
54794fc823
|
@ -811,7 +811,7 @@ module Sinatra
|
|||
# Set configuration options for Sinatra and/or the app.
|
||||
# Allows scoping of settings for certain environments.
|
||||
def configure(*envs, &block)
|
||||
yield if envs.empty? || envs.include?(environment.to_sym)
|
||||
yield self if envs.empty? || envs.include?(environment.to_sym)
|
||||
end
|
||||
|
||||
# Use the specified Rack middleware
|
||||
|
|
|
@ -37,6 +37,18 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal 'Foo: ', response.body
|
||||
end
|
||||
end
|
||||
|
||||
it "passes the subclass to configure blocks" do
|
||||
ref = nil
|
||||
TestApp.configure { |app| ref = app }
|
||||
assert_equal TestApp, ref
|
||||
end
|
||||
|
||||
it "allows the configure block arg to be omitted and does not change context" do
|
||||
context = nil
|
||||
TestApp.configure { context = self }
|
||||
assert_equal self, context
|
||||
end
|
||||
end
|
||||
|
||||
describe "Sinatra::Base as Rack middleware" do
|
||||
|
|
Loading…
Reference in New Issue