2009-01-13 12:53:53 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
2008-12-13 16:06:02 -05:00
|
|
|
|
|
|
|
describe 'Static' do
|
|
|
|
F = ::File
|
|
|
|
|
|
|
|
before do
|
2009-01-13 12:53:53 -05:00
|
|
|
mock_app {
|
2008-12-13 16:06:02 -05:00
|
|
|
set :static, true
|
|
|
|
set :public, F.dirname(__FILE__)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'serves GET requests for files in the public directory' do
|
|
|
|
get "/#{F.basename(__FILE__)}"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal File.read(__FILE__), body
|
|
|
|
assert_equal File.size(__FILE__).to_s, response['Content-Length']
|
|
|
|
assert response.headers.include?('Last-Modified')
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'serves HEAD requests for files in the public directory' do
|
|
|
|
head "/#{F.basename(__FILE__)}"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal '', body
|
|
|
|
assert_equal File.size(__FILE__).to_s, response['Content-Length']
|
|
|
|
assert response.headers.include?('Last-Modified')
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'serves files in preference to custom routes' do
|
|
|
|
@app.get("/#{F.basename(__FILE__)}") { 'Hello World' }
|
|
|
|
get "/#{F.basename(__FILE__)}"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert body != 'Hello World'
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not serve directories' do
|
|
|
|
get "/"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert not_found?
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes to the next handler when the static option is disabled' do
|
|
|
|
@app.set :static, false
|
|
|
|
get "/#{F.basename(__FILE__)}"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert not_found?
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes to the next handler when the public option is nil' do
|
|
|
|
@app.set :public, nil
|
|
|
|
get "/#{F.basename(__FILE__)}"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert not_found?
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it '404s when a file is not found' do
|
|
|
|
get "/foobarbaz.txt"
|
2009-01-14 17:00:26 -05:00
|
|
|
assert not_found?
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
|
|
|
end
|