From f34923c1bcf5ab379e8d5769a4ebe4c81cc641aa Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 27 Mar 2012 13:35:10 -0700 Subject: [PATCH 1/4] fixed collection rename bug --- lib/collections/resources.js | 25 +++++++++++++------------ lib/resource.js | 2 +- lib/server.js | 4 ++-- test/resources.test.js | 8 ++++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/collections/resources.js b/lib/collections/resources.js index cf3728d..0427ef4 100644 --- a/lib/collections/resources.js +++ b/lib/collections/resources.js @@ -4,13 +4,13 @@ var collection = require('../types/collection'); -module.exports = +var resources = module.exports = require('../types/collection') .use('/resources') .use(function (req, res, next, end) { - if(req.method === 'PUT') { + var resource = req.data , collectionPath = resource.path , properties = resource && resource.properties @@ -20,14 +20,19 @@ module.exports = , errs = [] ; - end(function (req, res, next) { - if(!collectionPath) return next(); + if(resource.$renameFrom && (resource.$renameFrom != resource.path)) { + rename = resource.$renameFrom; - collection.use(collectionPath).rename(collectionPath.replace('/', ''), function (err) { + // dont insert renameFrom + delete resource.$renameFrom; + + // rename + collection.use(rename).rename(resource.path.replace('/', ''), function (err) { next(err); }); - }) - + + return; + } properties && Object.keys(properties).forEach(function (key) { prop = properties[key]; @@ -55,8 +60,4 @@ module.exports = next(); } }) -; - -// TODO -// - Run migration on PUT (when name is deleted remove property) -// - PUT requests come back {task: {$renameFrom: 'title'}} \ No newline at end of file +; \ No newline at end of file diff --git a/lib/resource.js b/lib/resource.js index b512cf2..cf7699c 100644 --- a/lib/resource.js +++ b/lib/resource.js @@ -14,7 +14,7 @@ var types = require('./types') module.exports = function (req, res, next, end) { var resource = req.resource , method = req.method; - + // skip without a resource if(!resource) return next({status: 404}); diff --git a/lib/server.js b/lib/server.js index e1c697a..ca09bc7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -35,7 +35,7 @@ var middleware = function (req, res, next) { */ middleware.listen = function (callback) { - var server = this.server = express.createServer(function (req, res, next) { + var server = this.server = express.createServer(function (req, res, next) { // by default pause the request req.pause(); @@ -136,7 +136,7 @@ middleware.listen = function (callback) { res.statusCode = err.status || 400; res.send({error: err}); } else { - next(err); + res.send(err); } }); diff --git a/test/resources.test.js b/test/resources.test.js index 7630397..1d28b59 100644 --- a/test/resources.test.js +++ b/test/resources.test.js @@ -66,14 +66,14 @@ describe('Application Resource Types', function(){ it('should rename the resource collection', function(done) { resources.get(function (e, all) { var res = all[0]; + res.$renameFrom = res.path; res.path = '/tasks'; todos.post({title: 'foo'}, function () { - resources.use('/' + res._id).put(res, function (err, upd) { + resources.use('/' + res._id).put(res, function (err) { unauthed.use('/tasks').get(function (ee, r) { - expect(r).to.exist; - client.use('/tasks').del(function () { - done(ee || e || err); + client.use('/tasks').del(function (err) { + done(); }) }) }) From 1b061c8eb3228e5dabfdd6ec6fdb52aee35ee8b8 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 27 Mar 2012 13:36:51 -0700 Subject: [PATCH 2/4] Release v0.3.2 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 496c19e..be7dc05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Ritchie Martori", "name": "deployd", - "version": "0.3.1", + "version": "0.3.2", "repository": { "url": "git://github.com/deployd/deployd.git" }, @@ -11,8 +11,8 @@ "main":"index", "dependencies": { "mdoq": "0.8.6", - "mdoq-http": "0.4.1", - "mdoq-mongodb": "0.4.3", + "mdoq-http": "0.4.x", + "mdoq-mongodb": "0.4.x", "revalidator": "0.1.x", "commander": "0.5.x", "express": "2.5.x" From 90c7f2c5ea1b4c2964f0a2bf9e83bf2190df7d0d Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 27 Mar 2012 17:34:00 -0700 Subject: [PATCH 3/4] removed old and incomplete tests, rebuilt dashboard --- Makefile | 4 +-- dashboard/index.html | 29 +++++++++++--------- dashboard/js/app.js | 18 +++++++------ dashboard/stylesheets/style.css | 11 ++++---- lib/server.js | 20 -------------- test/dashboard.test.js | 12 ++++----- test/router.test.js | 16 +++++------ test/support/out-eg.jpg | Bin 0 -> 1128431 bytes test/xdomain.test.js | 46 ++++++++++++++++---------------- 9 files changed, 71 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index da62b81..f995163 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ test: @mocha -build: +dashboard: node ../dashboard/make build rm -rf dashboard cp -r ../dashboard/build dashboard - + .PHONY: test \ No newline at end of file diff --git a/dashboard/index.html b/dashboard/index.html index e1844f2..651c335 100644 --- a/dashboard/index.html +++ b/dashboard/index.html @@ -82,16 +82,14 @@