Skip to content
Myr

spec.plugins.static.js

This file

Path

spec/spec.plugins.static.js

104 lines · 3.4 KiB · JavaScript

Last changed by

Merge branch 'integration'visionmediabefore adoption7441164

History of this file

Take it

Closes #88.visionmediabefore adoptionb8f54d6

lines 1–53why, one step back
1
2describe 'Express'3 describe 'StaticFile'4 before5 StaticFile = require('express/plugins/static').File6 use(require('express/plugins/static').Static, { path: 'spec/fixtures' })7 end8 9 describe '#constructor'10 it 'should accept and assign #path'11 (new StaticFile('/foo/bar')).path.should.eql '/foo/bar'12 end13 14 it 'should throw an InvalidPathError when .. is found'15 // TODO: use throw_error when fixed...16 try { new StaticFile('/../foobar') }17 catch (e) {18 e.name.should.eql 'InvalidPathError'19 e.message.should.eql "`/../foobar' is not a valid path"20 }21 end22 end23 24 describe 'GET /public/*'25 it 'should transfer static files'26 get('/public/user.json').body.should.include '"name":'27 end28 end29 30 describe '#sendfile()'31 describe 'when the file exists'32 it 'should transfer the file'33 get('/public/*', function(file){34 this.sendfile('spec/fixtures/' + file)35 })36 get('/public/user.json').body.should.include '"name":'37 end38 39 it 'should automatically set the content type based on extension'40 get('/public/*', function(file){41 this.sendfile('spec/fixtures/' + file)42 })43 get('/public/user.json').headers['content-type'].should.eql 'application/json'44 end45 end46 47 describe 'when "cache static files" is enabled'48 it 'should transfer the file'49 enable('cache static files')50 get('/public/*', function(file){51 this.sendfile('spec/fixtures/' + file)52 })53 get('/cached', function(){

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 54–57why, one step back
54 var self = this
55 this.cache.get('static:spec/fixtures/user.json', function(val){56 self.halt(200, val ? 'yes' : 'no')57 })

Closes #88.visionmediabefore adoptionb8f54d6

lines 58–76why, one step back
58 })
59 get('/cached').body.should.eql 'no'60 get('/public/user.json').body.should.include '"name":'61 get('/cached').body.should.eql 'yes'62 get('/cached').body.should.eql 'yes'63 end64 65 it 'should automatically set the content type based on extension'66 enable('cache static files')67 get('/public/*', function(file){68 this.sendfile('spec/fixtures/' + file)69 })70 get('/public/user.json').headers['content-type'].should.eql 'application/json'71 get('/public/user.json').headers['content-type'].should.eql 'application/json'72 get('/public/user.json').headers['content-type'].should.eql 'application/json'73 end74 end75 end76

Merge branch 'integration'visionmediabefore adoption7441164

lines 77–102why, one step back
77 describe '#download()'
78 describe 'when the file exists'79 it 'should set attachment filename'80 get('/report', function(){81 this.download('report.pdf')82 return 'foo'83 })84 get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'85 end86 87 it 'should transfer the file'88 get('/public/*', function(file){89 this.download('spec/fixtures/' + file)90 })91 get('/public/user.json').body.should.include '"name":'92 end93 94 it 'should automatically set the content type based on extension'95 get('/public/*', function(file){96 this.download('spec/fixtures/' + file)97 })98 get('/public/user.json').headers['content-type'].should.eql 'application/json'99 end100 end101 end102

Closes #88.visionmediabefore adoptionb8f54d6

lines 103–104why, one step back
103 end
104end