Fixed some cookie 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 14befd6 · Browse files · 3 files·+28 added−26 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+28 added−26 removed
- tests:+7 added−5 removed
- other:+21 added−21 removed
Provenance
- Commit
7ca5942- Tree
f97788c- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
14befd6
3 files changed+28 added−26 removed
modified:lib/express/plugins/cookie.js+21 added-21 removed
36 unmodified lines3738394041424344454647484142505152535455564344454647484950515253585455565758596061606162636465666768686970717273727374757636 unmodified lines return key + '=' + val }).toArray().join('; ')}
/** * Get or set cookie values. * * @param {string} key * @param {string} val * @return {string} * @api public */// --- Request
exports.cookie = function(key, val) { return val === undefined ? Express.server.request.cookie[key] : (Express.server.response.cookie = Express.server.response.cookie || {})[key] = val}Request.include({ /** * Get or set cookie values. * * @param {string} key * @param {string} val * @return {string} * @api public */
// --- Expose cookie: function(key, val) { if (!this.response.cookie) this.response.cookie[key] = {} return val === undefined ? this.response.cookie[key] : this.response.cookie[key] = val } })
process.mixin(GLOBAL, exports)
// --- Cookie
exports.Cookie = Plugin.extend({ on: { request: function(event) { if (event.request.headers.cookie) event.request.cookie = exports.parseCookie(event.request.headers.cookie) event.request.response.cookie = exports.parseCookie(event.request.headers.cookie) }, response: function(event) { if (event.response.cookie) header('set-cookie', exports.compileCookie(event.response.cookie)) if (event.request.response.cookie) event.request.header('set-cookie', exports.compileCookie(event.request.response.cookie)) } }})No newline at end of fileNo newline at end of filemodified:spec/spec.plugins.cookie.js+6 added-4 removed
123456789101148 unmodified lines606162636264656667686970717271727374757677789 unmodified lines888990919092939495963 unmodified lines
describe 'Express' before_each reset() use(require('express/plugins/cookie').Cookie) compileCookie = require('express/plugins/cookie').compileCookie parseCookie = require('express/plugins/cookie').parseCookie end describe 'Cookie' describe 'compileCookie()'48 unmodified lines describe 'on' describe 'request' it 'should parse the Cookie header' get('/user', function(){ return Express.server.request.cookie['foo'] return this.cookie('foo') }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end end describe 'response' it 'should set the Set-Cookie header' get('/user', function(){ cookie('SID', '732423sdfs73243') cookie('path', '/') this.cookie('SID', '732423sdfs73243') this.cookie('path', '/') return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/' end9 unmodified lines describe 'cookie()' it 'should get request cookie values' get('/user', function(){ return cookie('foo') return this.cookie('foo') }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end end3 unmodified linesmodified:spec/spec.plugins.redirect.js+1 added-1 removed
7 unmodified lines8 describe 'Redirect'9 describe 'redirect()'10 it 'should set status to 302'11 get('/logout', function(){12- redirect('/')12+ this.redirect('/')13 })14 get('/logout').status.should.eql 30215 get('/logout').headers['location'].should.eql '/'16 end46 unmodified lines