Skip to content
Browse files

Base enables static by default if public is set and exists

  • Loading branch information...
1 parent 9cf0c0d commit fe1453440abe8dc582cfb2ccc066efe16891863e @rtomayko rtomayko committed
Showing with 15 additions and 6 deletions.
  1. +2 −2 lib/sinatra/base.rb
  2. +13 −4 test/options_test.rb
  3. 0 test/public/favicon.ico
View
4 lib/sinatra/base.rb
@@ -1011,7 +1011,6 @@ def caller_locations
set :sessions, false
set :logging, false
set :method_override, false
- set :static, false
set :environment, (ENV['RACK_ENV'] || :development).to_sym
set :run, false
@@ -1023,6 +1022,7 @@ def caller_locations
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
set :views, Proc.new { root && File.join(root, 'views') }
set :public, Proc.new { root && File.join(root, 'public') }
+ set :static, Proc.new { self.public && File.exist?(self.public) }
set :lock, false
class << self
@@ -1089,8 +1089,8 @@ class Default < Base
set :sessions, false
set :logging, Proc.new { ! test? }
set :method_override, 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
View
17 test/options_test.rb
@@ -283,16 +283,25 @@ def clean_backtrace(trace)
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 Default' do
assert @default.static?
end
-
- # TODO: it setup static routes if public is enabled
- # TODO: however, that's already tested in static_test so...
end
describe 'host' do
View
0 test/public/favicon.ico
No changes.

0 comments on commit fe14534

Please sign in to comment.
Something went wrong with that request. Please try again.