Added res.download() tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent a5be68b · Browse files · 2 files·+82 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+82 added−2 removed
- tests:+78 added−0 removed
- other:+4 added−2 removed
Provenance
- Commit
5840b42- Tree
7fa7f4e- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
a5be68b
2 files changed+82 added−2 removed
modified:lib/response.js+4 added-2 removed
249 unmodified lines250 * and optional callback `fn(err)`. The callback is invoked251 * when the data transfer is complete, or when an error has252 * ocurred. Be sure to check `res.headerSent` if you plan to respond.253 *254- * This method uses `res.attachment()` and `res.sendfile()`.254+ * This method uses `res.sendfile()`.255 *256 * @param {String} path257 * @param {String|Function} filename or fn258 * @param {Function} fn6 unmodified lines265 fn = filename;266 filename = null;267 }268 269- return this.attachment(filename || path).sendfile(path, fn);269+ filename = filename || path;270+ this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');271+ return this.sendfile(path, fn);272 };273 274 /**275 * Set _Content-Type_ response header with `type` through `mime.lookup()`373 unmodified linesadded:test/res.download.js+78 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
var express = require('../') , request = require('./support/http') , assert = require('assert');
describe('res', function(){ describe('.download(path)', function(){ it('should transfer as an attachment', function(done){ var app = express();
app.use(function(req, res){ res.download('test/fixtures/user.html'); });
request(app) .get('/') .end(function(res){ res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); res.should.have.header('Content-Disposition', 'attachment; filename="user.html"'); done(); }); }) })
describe('.download(path, filename)', function(){ it('should provide an alternate filename', function(done){ var app = express();
app.use(function(req, res){ res.download('test/fixtures/user.html', 'document'); });
request(app) .get('/') .end(function(res){ res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); res.should.have.header('Content-Disposition', 'attachment; filename="document"'); done(); }); }) })
describe('.download(path, fn)', function(){ it('should invoke the callback', function(done){ var app = express() , calls = 0;
app.use(function(req, res){ res.download('test/fixtures/user.html', done); });
request(app) .get('/') .end(function(res){ res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); res.should.have.header('Content-Disposition', 'attachment; filename="user.html"'); }); }) })
describe('.download(path, filename, fn)', function(){ it('should invoke the callback', function(done){ var app = express() , calls = 0;
app.use(function(req, res){ res.download('test/fixtures/user.html', 'document', done); });
request(app) .get('/') .end(function(res){ res.should.have.header('Content-Type', 'text/html; charset=UTF-8'); res.should.have.header('Content-Disposition', 'attachment; filename="document"'); }); }) })})