Skip to content
Myr

Added Request#sendfile() specs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent ebcfb0e · Browse files · 3 files+82 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+82 added−8 removed

  • tests:+78 added−4 removed
  • other:+4 added−4 removed

3 files+82 added−8 removed

modified:lib/express/spec/mocks.js+32 added-3 removed
modified:lib/express/static.js+4 added-4 removed
43 unmodified lines
44 return request.contentType(cache.type),45 request.halt(200, cache.content, 'binary')46 path.exists(file, function(exists){47 if (!exists) return request.halt()48 fs.stat(file, function(e, stats){49 if (e) throw e48 fs.stat(file, function(err, stats){49 if (err) throw err50 if (!stats.isFile()) return request.halt()51 fs.readFile(file, 'binary', function(e, content){52 if (e) throw e51 fs.readFile(file, 'binary', function(err, content){52 if (err) throw err53 request.contentType(file)54 if (set('cache static files'))55 request.cache.set(file, { type: file, content: content })56 request.halt(200, content, 'binary')
5 unmodified lines
modified:spec/spec.static.js+46 added-1 removed
3 unmodified lines
4 before5 StaticFile = require('express/static').File6 end7 8 describe '#init'8 describe '#constructor'9 it 'should accept and assign #path'10 (new StaticFile('/foo/bar')).path.should.eql '/foo/bar'11 end12
5 unmodified lines
18 e.message.should.eql "`/../foobar' is not a valid path"19 }20 end21 end22 23 describe '#sendfile()'24 describe 'when the file exists'25 it 'should transfer the file'26 get('/public/*', function(file){27 this.sendfile('spec/fixtures/' + file)28 })29 get('/public/user.json').body.should.include '"name":'30 end31 32 it 'should automatically set the content type based on extension'33 get('/public/*', function(file){34 this.sendfile('spec/fixtures/' + file)35 })36 get('/public/user.json').headers['content-type'].should.eql 'application/json'37 end38 end39 40 describe 'when "cache static files" is enabled'41 it 'should transfer the file'42 enable('cache static files')43 get('/public/*', function(file){44 this.sendfile('spec/fixtures/' + file)45 })46 get('/cached', function(){47 return this.cache.get('spec/fixtures/user.json') ? 'yes' : 'no'48 })49 get('/cached').body.should.eql 'no'50 get('/public/user.json').body.should.include '"name":'51 get('/cached').body.should.eql 'yes'52 get('/cached').body.should.eql 'yes'53 end54 55 it 'should automatically set the content type based on extension'56 enable('cache static files')57 get('/public/*', function(file){58 this.sendfile('spec/fixtures/' + file)59 })60 get('/public/user.json').headers['content-type'].should.eql 'application/json'61 get('/public/user.json').headers['content-type'].should.eql 'application/json'62 get('/public/user.json').headers['content-type'].should.eql 'application/json'63 end64 end65 end66 67 end68end