Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

… apps
  • Loading branch information...
commit db761b8b07fbb9beac545e2779f90d254197deb4 1 parent cf0ed2b
@rkh rkh authored
View
3  CHANGES
@@ -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
2  README.rdoc
@@ -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
2  lib/sinatra/base.rb
@@ -1310,6 +1310,7 @@ def detect_rack_handler
def inherited(subclass)
subclass.reset!
+ subclass.set :app_file, caller_files.first unless subclass.app_file?
super
end
@@ -1471,6 +1472,7 @@ class Application < Base
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
14 test/settings_test.rb
@@ -3,10 +3,10 @@
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 @@ def foo=(value)
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
Please sign in to comment.
Something went wrong with that request. Please try again.