2008-02-24 19:04:18 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
|
|
|
|
|
|
|
context "Static files (by default)" do
|
|
|
|
|
2008-03-10 03:31:19 -04:00
|
|
|
setup do
|
|
|
|
Sinatra.application = nil
|
2008-02-24 19:04:18 -05:00
|
|
|
Sinatra.application.options.public = File.dirname(__FILE__) + '/public'
|
2008-03-10 03:31:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "are served from root/public" do
|
2008-02-24 19:04:18 -05:00
|
|
|
get_it '/foo.xml'
|
|
|
|
should.be.ok
|
|
|
|
headers['Content-Length'].should.equal '12'
|
|
|
|
headers['Content-Type'].should.equal 'application/xml'
|
|
|
|
body.should.equal "<foo></foo>\n"
|
|
|
|
end
|
2008-03-10 03:31:19 -04:00
|
|
|
|
|
|
|
specify "are not served when verb is not GET or HEAD" do
|
|
|
|
post_it '/foo.xml'
|
|
|
|
# these should actually be giving back a 405 Method Not Allowed but that
|
|
|
|
# complicates the routing logic quite a bit.
|
|
|
|
should.be.not_found
|
|
|
|
status.should.equal 404
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "are served when verb is HEAD but missing a body" do
|
|
|
|
head_it '/foo.xml'
|
|
|
|
should.be.ok
|
|
|
|
headers['Content-Length'].should.equal '12'
|
|
|
|
headers['Content-Type'].should.equal 'application/xml'
|
|
|
|
body.should.equal ""
|
|
|
|
end
|
|
|
|
|
|
|
|
# static files override dynamic/internal events and ...
|
|
|
|
specify "are served when conflicting events exists" do
|
|
|
|
get '/foo.xml' do
|
|
|
|
'this is not foo.xml!'
|
|
|
|
end
|
|
|
|
get_it '/foo.xml'
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal "<foo></foo>\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "are irrelevant when request_method is not GET/HEAD" do
|
|
|
|
put '/foo.xml' do
|
|
|
|
'putted!'
|
|
|
|
end
|
|
|
|
put_it '/foo.xml'
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal 'putted!'
|
|
|
|
|
|
|
|
get_it '/foo.xml'
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal "<foo></foo>\n"
|
|
|
|
end
|
|
|
|
|
2008-03-26 10:51:08 -04:00
|
|
|
specify "include a Last-Modified header" do
|
|
|
|
last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
|
|
|
|
get_it('/foo.xml')
|
|
|
|
should.be.ok
|
|
|
|
body.should.not.be.empty
|
|
|
|
headers['Last-Modified'].should.equal last_modified.httpdate
|
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
# Deprecated. Use: ConditionalGet middleware.
|
2008-03-26 10:51:08 -04:00
|
|
|
specify "are not served when If-Modified-Since matches" do
|
|
|
|
last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
|
|
|
|
@request = Rack::MockRequest.new(Sinatra.application)
|
|
|
|
@response = @request.get('/foo.xml', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate)
|
|
|
|
status.should.equal 304
|
|
|
|
body.should.be.empty
|
|
|
|
end
|
|
|
|
|
2008-03-26 12:54:14 -04:00
|
|
|
specify "should omit Content-Disposition headers" do
|
|
|
|
get_it('/foo.xml')
|
|
|
|
should.be.ok
|
|
|
|
headers['Content-Disposition'].should.be.nil
|
|
|
|
headers['Content-Transfer-Encoding'].should.be.nil
|
|
|
|
end
|
|
|
|
|
2008-04-26 18:09:40 -04:00
|
|
|
specify "should be served even if their path is url escaped" do
|
|
|
|
get_it('/fo%6f.xml')
|
|
|
|
should.be.ok
|
|
|
|
body.should.equal "<foo></foo>\n"
|
|
|
|
end
|
|
|
|
|
2008-02-24 19:04:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "SendData" do
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-02-24 19:04:18 -05:00
|
|
|
setup do
|
|
|
|
Sinatra.application = nil
|
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
# Deprecated. send_data is going away.
|
2009-02-22 02:26:55 -05:00
|
|
|
specify "should send the data with options" do
|
2008-02-24 19:04:18 -05:00
|
|
|
get '/' do
|
|
|
|
send_data 'asdf', :status => 500
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-02-24 19:04:18 -05:00
|
|
|
get_it '/'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-02-24 19:04:18 -05:00
|
|
|
should.be.server_error
|
|
|
|
body.should.equal 'asdf'
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
# Deprecated. The Content-Disposition is no longer handled by sendfile.
|
2009-01-25 00:29:18 -05:00
|
|
|
xspecify "should include a Content-Disposition header" do
|
2008-03-26 12:54:14 -04:00
|
|
|
get '/' do
|
|
|
|
send_file File.dirname(__FILE__) + '/public/foo.xml'
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/'
|
|
|
|
|
|
|
|
should.be.ok
|
|
|
|
headers['Content-Disposition'].should.not.be.nil
|
|
|
|
headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
|
|
|
|
headers['Content-Transfer-Encoding'].should.equal 'binary'
|
|
|
|
end
|
|
|
|
|
2009-01-25 00:29:18 -05:00
|
|
|
specify "should include a Content-Disposition header when :disposition set to attachment" do
|
|
|
|
get '/' do
|
|
|
|
send_file File.dirname(__FILE__) + '/public/foo.xml',
|
|
|
|
:disposition => 'attachment'
|
|
|
|
end
|
|
|
|
|
|
|
|
get_it '/'
|
|
|
|
|
|
|
|
should.be.ok
|
|
|
|
headers['Content-Disposition'].should.not.be.nil
|
|
|
|
headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
|
|
|
|
end
|
2008-02-24 19:04:18 -05:00
|
|
|
end
|