From 64fd4210ce99d92f549f2369d9e325c83601988d Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 27 Mar 2012 09:32:49 -0700 Subject: [PATCH] added collection renaming --- lib/collections/resources.js | 11 +++++++++++ test/resources.test.js | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/collections/resources.js b/lib/collections/resources.js index a1bea3a..86e6f7c 100644 --- a/lib/collections/resources.js +++ b/lib/collections/resources.js @@ -20,6 +20,17 @@ module.exports = , errs = [] ; + end(function (req, res, next) { + if(!collectionPath) return next(); + + console.log('rename to', collectionPath.replace('/', '')); + + collection.use(collectionPath).rename(collectionPath.replace('/', ''), function (err) { + next(err); + }); + }) + + properties && Object.keys(properties).forEach(function (key) { prop = properties[key]; rename = prop.$renameFrom; diff --git a/test/resources.test.js b/test/resources.test.js index 06c39df..7630397 100644 --- a/test/resources.test.js +++ b/test/resources.test.js @@ -62,6 +62,26 @@ describe('Application Resource Types', function(){ }) }) + describe('PUT /resources/', function(){ + it('should rename the resource collection', function(done) { + resources.get(function (e, all) { + var res = all[0]; + res.path = '/tasks'; + + todos.post({title: 'foo'}, function () { + resources.use('/' + res._id).put(res, function (err, upd) { + unauthed.use('/tasks').get(function (ee, r) { + expect(r).to.exist; + client.use('/tasks').del(function () { + done(ee || e || err); + }) + }) + }) + }) + }) + }) + }) + describe('PUT /resources/', function(){ it('should rename change properties on any existing data', function(done) { var exTodo = {title: 'feed fido', completed: true};