2012-05-10 17:11:43 -07:00
|
|
|
|
|
|
|
|
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('/')
|
2012-06-26 17:14:07 -07:00
|
|
|
.end(function(err, res){
|
2012-05-10 17:11:43 -07:00
|
|
|
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
|
|
|
|
|
res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');
|
2012-06-26 17:14:07 -07:00
|
|
|
res.text.should.equal('<p>{{user.name}}</p>');
|
2012-05-10 17:11:43 -07:00
|
|
|
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('/')
|
2012-06-26 17:14:07 -07:00
|
|
|
.end(function(err, res){
|
2012-05-10 17:11:43 -07:00
|
|
|
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('/')
|
2012-06-26 17:14:07 -07:00
|
|
|
.end(function(err, res){
|
2012-05-10 17:11:43 -07:00
|
|
|
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('/')
|
2012-06-26 17:14:07 -07:00
|
|
|
.end(function(err, res){
|
2012-05-10 17:11:43 -07:00
|
|
|
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
|
|
|
|
|
res.should.have.header('Content-Disposition', 'attachment; filename="document"');
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|