1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Base enables static by default if public is set and exists

This commit is contained in:
Ryan Tomayko 2010-01-28 07:53:42 -08:00
parent 4d7d3636af
commit de6d6d6657
3 changed files with 17 additions and 4 deletions

View file

@ -1029,7 +1029,6 @@ module Sinatra
set :sessions, false
set :logging, false
set :methodoverride, false
set :static, false
set :environment, (ENV['RACK_ENV'] || :development).to_sym
set :run, false # start server via at-exit hook?
@ -1040,11 +1039,13 @@ module Sinatra
set :app_file, nil
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
set :public, Proc.new { root && File.join(root, 'public') }
set :views, Proc.new { root && File.join(root, 'views') }
set :reload_templates, Proc.new { !development? }
set :lock, false
set :public, Proc.new { root && File.join(root, 'public') }
set :static, Proc.new { self.public && File.exist?(self.public) }
error ::Exception do
response.status = 500
content_type 'text/html'
@ -1093,8 +1094,8 @@ module Sinatra
set :sessions, false
set :logging, Proc.new { ! test? }
set :methodoverride, true
set :static, true
set :run, Proc.new { ! test? }
set :static, true
def self.register(*extensions, &block) #:nodoc:
added_methods = extensions.map {|m| m.public_instance_methods }.flatten

0
test/public/favicon.ico Normal file
View file

View file

@ -274,10 +274,22 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'static' do
it 'is disabled on Base' do
it 'is disabled on Base by default' do
assert ! @base.static?
end
it 'is enabled on Base when public is set and exists' do
@base.set :environment, :development
@base.set :public, File.dirname(__FILE__)
assert @base.static?
end
it 'is enabled on Base when root is set and root/public exists' do
@base.set :environment, :development
@base.set :root, File.dirname(__FILE__)
assert @base.static?
end
it 'is enabled on Application' do
assert @application.static?
end