mirror of https://gitee.com/bigwinds/arangodb
Tiny additions to Frank
* Missing templates will result in an error * The middleware calls next * All JSLint warnings except one fixed
This commit is contained in:
parent
7189151f93
commit
3d59723f99
|
@ -1,12 +1,15 @@
|
||||||
|
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, plusplus: true */
|
||||||
|
/*global _, require, db, exports */
|
||||||
|
|
||||||
var Frank,
|
var Frank,
|
||||||
baseMiddleware,
|
BaseMiddleware,
|
||||||
_ = require("underscore"),
|
_ = require("underscore"),
|
||||||
internal = {};
|
internal = {};
|
||||||
|
|
||||||
internal.createUrlObject = function (url, constraint, method) {
|
internal.createUrlObject = function (url, constraint, method) {
|
||||||
var urlObject = {};
|
var urlObject = {};
|
||||||
|
|
||||||
if(!_.isString(url)) {
|
if (!_.isString(url)) {
|
||||||
throw "URL has to be a String";
|
throw "URL has to be a String";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +40,8 @@ Frank = function (options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(templateCollection)) {
|
if (_.isString(templateCollection)) {
|
||||||
this.routingInfo.templateCollection = db._collection(templateCollection) || db._create(templateCollection);
|
this.routingInfo.templateCollection = db._collection(templateCollection) ||
|
||||||
|
db._create(templateCollection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ _.extend(Frank.prototype, {
|
||||||
|
|
||||||
delete: function (route, argument1, argument2) {
|
delete: function (route, argument1, argument2) {
|
||||||
this.handleRequest("delete", route, argument1, argument2);
|
this.handleRequest("delete", route, argument1, argument2);
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,7 +129,11 @@ BaseMiddleware = function (templateCollection) {
|
||||||
throw "No template collection has been provided when creating a new Frank";
|
throw "No template collection has been provided when creating a new Frank";
|
||||||
}
|
}
|
||||||
|
|
||||||
template = templateCollection.firstExample({path: "simple/path"});
|
template = templateCollection.firstExample({path: templatePath });
|
||||||
|
|
||||||
|
if (_.isNull(template)) {
|
||||||
|
throw "Template '" + templatePath + "' does not exist";
|
||||||
|
}
|
||||||
|
|
||||||
if (template.templateLanguage !== "underscore") {
|
if (template.templateLanguage !== "underscore") {
|
||||||
throw "Unknown template language '" + template.templateLanguage + "'";
|
throw "Unknown template language '" + template.templateLanguage + "'";
|
||||||
|
@ -137,6 +145,8 @@ BaseMiddleware = function (templateCollection) {
|
||||||
};
|
};
|
||||||
|
|
||||||
response = _.extend(response, responseFunctions);
|
response = _.extend(response, responseFunctions);
|
||||||
|
|
||||||
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
return middleware;
|
return middleware;
|
||||||
|
|
|
@ -243,6 +243,18 @@ function BaseMiddlewareWithoutTemplateSpec () {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(error, "No template collection has been provided when creating a new Frank");
|
assertEqual(error, "No template collection has been provided when creating a new Frank");
|
||||||
|
},
|
||||||
|
|
||||||
|
testMiddlewareCallsTheAction: function () {
|
||||||
|
var actionWasCalled = false;
|
||||||
|
|
||||||
|
next = function () {
|
||||||
|
actionWasCalled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
baseMiddleware(request, response, options, next);
|
||||||
|
|
||||||
|
assertTrue(actionWasCalled);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -303,11 +315,28 @@ function BaseMiddlewareWithTemplateSpec () {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(error, "Unknown template language 'pirateEngine'");
|
assertEqual(error, "Unknown template language 'pirateEngine'");
|
||||||
|
},
|
||||||
|
|
||||||
|
testRenderingATemplateWithAnNotExistingTemplate: function () {
|
||||||
|
var myCollection, error, middleware;
|
||||||
|
|
||||||
|
internal.db._drop("templateTest");
|
||||||
|
myCollection = internal.db._create("templateTest");
|
||||||
|
|
||||||
|
middleware = new BaseMiddleware(myCollection);
|
||||||
|
middleware(request, response, options, next);
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.render("simple/path", { username: "moonglum" });
|
||||||
|
} catch(e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEqual(error, "Template 'simple/path' does not exist");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jsunity.run(CreateFrankSpec);
|
jsunity.run(CreateFrankSpec);
|
||||||
jsunity.run(SetRoutesFrankSpec);
|
jsunity.run(SetRoutesFrankSpec);
|
||||||
jsunity.run(BaseMiddlewareWithoutTemplateSpec);
|
jsunity.run(BaseMiddlewareWithoutTemplateSpec);
|
||||||
|
|
Loading…
Reference in New Issue