Updated resource example with acceptnce test.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Robert Sköld · committed by TJ Holowaychuk · parent a153082 · Browse files · 2 files·+70 added−4 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+70 added−4 removed
- tests:+64 added−0 removed
- other:+6 added−4 removed
Provenance
- Commit
8120a06- Tree
5d04249- Author
Robert Sköld <robert@publicclass.se>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
a153082
2 files changed+70 added−4 removed
modified:examples/resource/app.js+6 added-4 removed
1234566788910111271 unmodified lines84858687888889899091
/** * Module dependencies. */
var express = require('../../lib/express');var express = require('../../');
var app = express.createServer();var app = module.exports = express();
// Ad-hoc example resource method
app.resource = function(path, obj) {71 unmodified lines , '</ul>' ].join('\n')); });
if (!module.parent) {app.listen(3000);console.log('Express app started on port 3000'); app.listen(3000); console.log('Express started on port 3000');}No newline at end of fileadded:test/acceptance/resource.js+64 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364var app = require('../../examples/resource/app') , request = require('../support/http');
describe('resource', function(){ describe('GET /', function(){ it('should respond with instructions', function(done){ request(app) .get('/') .expect(/^<h1>Examples:<\/h1>/,done) }) })
describe('GET /users', function(){ it('should respond with all users', function(done){ request(app) .get('/users') .expect(/^\[{"name":"tj"},{"name":"ciaran"},{"name":"aaron"},{"name":"guillermo"},{"name":"simon"},{"name":"tobi"}\]/,done) }) })
describe('GET /users/1', function(){ it('should respond with user 1', function(done){ request(app) .get('/users/1') .expect(/^{"name":"ciaran"}/,done) }) })
describe('GET /users/1..3', function(){ it('should respond with users 1 through 3', function(done){ request(app) .get('/users/1..3') .expect(/^<ul><li>ciaran<\/li>\n<li>aaron<\/li>\n<li>guillermo<\/li><\/ul>/,done) }) })
describe('DELETE /users/1', function(){ it('should respond with users 1 through 3', function(done){ request(app) .delete('/users/1') .expect(/^destroyed/,done) }) })
describe('GET /users/1..3.json', function(){ it('should respond with users 2 and 3 as json', function(done){ request(app) .get('/users/1..3.json') .expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done) }) })})// curl http://localhost:3000/users -- responds with all users// curl http://localhost:3000/users/1 -- responds with user 1// curl http://localhost:3000/users/4 -- responds with error// curl http://localhost:3000/users/1..3 -- responds with several users// curl -X DELETE http://localhost:3000/users/1 -- deletes the user
// , '<li>GET /users</li>' // , '<li>GET /users/1</li>' // , '<li>GET /users/3</li>' // , '<li>GET /users/1..3</li>' // , '<li>GET /users/1..3.json</li>' // , '<li>DELETE /users/4</li>'No newline at end of file