Skip to content

Commit

Permalink
Adding support for GET _uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
watchforstock committed May 5, 2015
1 parent 4e91132 commit 40b25f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Visit the [Mock Couch website](http://chris-l.github.io/mock-couch/).
- also, using `_all_docs` with POST to specify the desired keys
- GET the information of a database
- GET `_all_dbs`
- GET `_uuids`
- GET views (like `http://localhost:5984/database/_design/myviews/_view/someview/`)
- PUT one document
- PUT a database
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function MockCouch(options) {
this.sequence = {};

(function (server, self) {
var all_dbs, all_docs, get_db, get_changes, get_view, get_doc, put_doc;
var all_dbs, all_docs, get_db, get_changes, get_view, get_doc, put_doc, get_uuids;
/**
* Add the routes
*/
Expand All @@ -72,6 +72,10 @@ function MockCouch(options) {
server.get('/_all_dbs', all_dbs);
server.head('/_all_dbs', all_dbs);

// GET _uuids
get_uuids = require('./lib/uuids')(self);
server.get('/_uuids', get_uuids);

// PUT a database
server.put('/:db', require('./lib/put_db')(self));

Expand Down
22 changes: 22 additions & 0 deletions lib/uuids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*jslint node: true, indent: 2, nomen : true */
'use strict';

module.exports = function (self) {
/**
* GET method used to show a generate one or more UUIDs
*/
return function (req, res) {
var count, ret, i;

count = req.params.count || 1;

ret = [];

for (i = 0; i < count; i += 1) {
ret.push(i);
}

res.send(200, {'uuids': ret});
return self.emit('GET', { type : 'uuids', count : count });
};
};

0 comments on commit 40b25f9

Please sign in to comment.