let app_file default to the file subclassing Sinatra::Base in modular apps

This commit is contained in:
Konstantin Haase 2011-05-03 20:17:02 +02:00
parent cf0ed2b0ec
commit db761b8b07
4 changed files with 15 additions and 6 deletions

View File

@ -10,6 +10,9 @@
explicitly to prevent that behavior. (Magnus Holm, Ryan Tomayko, Konstantin
Haase)
* `settings.app_file` now defaults to the file subclassing `Sinatra::Base` in
modular applications. (Konstantin Haase)
* Set up `Rack::Logger` or `Rack::NullLogger` depending on whether logging
was enabled or not. Also, expose that logger with the `logger` helper
method. (Konstantin Haase)

View File

@ -1382,7 +1382,7 @@ different default settings:
Setting Classic Modular
app_file file loading sinatra nil
app_file file loading sinatra file subclassing Sinatra::Base
run $0 == app_file false
logging true false
method_override true false

View File

@ -1310,6 +1310,7 @@ module Sinatra
def inherited(subclass)
subclass.reset!
subclass.set :app_file, caller_files.first unless subclass.app_file?
super
end
@ -1471,6 +1472,7 @@ module Sinatra
set :method_override, true
set :run, Proc.new { ! test? }
set :session_secret, Proc.new { super() unless development? }
set :app_file, nil
def self.register(*extensions, &block) #:nodoc:
added_methods = extensions.map {|m| m.public_instance_methods }.flatten

View File

@ -3,10 +3,10 @@ require File.dirname(__FILE__) + '/helper'
class SettingsTest < Test::Unit::TestCase
setup do
@base = Sinatra.new(Sinatra::Base)
@base.set :environment, :foo
@base.set :environment => :foo, :app_file => nil
@application = Sinatra.new(Sinatra::Application)
@application.set :environment, :foo
@application.set :environment => :foo, :app_file => nil
end
it 'sets settings to literal values' do
@ -358,9 +358,13 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'app_file' do
it 'is nil' do
assert_nil @base.app_file
assert_nil @application.app_file
it 'is nil for base classes' do
assert_nil Sinatra::Base.app_file
assert_nil Sinatra::Application.app_file
end
it 'defaults to the file subclassing' do
assert_equal __FILE__, Sinatra.new.app_file
end
end