Make static files work with Rack::Lint in the pipeline [#121]

This commit is contained in:
Ryan Tomayko 2009-01-21 11:37:56 -08:00
parent 52658061d1
commit c0a2fbc8b1
2 changed files with 11 additions and 0 deletions

View File

@ -142,6 +142,7 @@ module Sinatra
class StaticFile < ::File #:nodoc:
alias_method :to_path, :path
def each
rewind
while buf = read(8192)
yield buf
end

View File

@ -18,6 +18,16 @@ describe 'Static' do
assert response.headers.include?('Last-Modified')
end
it 'produces a body that can be iterated over multiple times' do
env = Rack::MockRequest.env_for("/#{F.basename(__FILE__)}")
status, headers, body = @app.call(env)
buf1, buf2 = [], []
body.each { |part| buf1 << part }
body.each { |part| buf2 << part }
assert_equal buf1.join, buf2.join
assert_equal File.read(__FILE__), buf1.join
end
it 'serves HEAD requests for files in the public directory' do
head "/#{F.basename(__FILE__)}"
assert ok?