1
0
Fork 0

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:
Lucas Dohmen 2013-01-15 15:45:47 +01:00
parent 7189151f93
commit 3d59723f99
2 changed files with 59 additions and 20 deletions

View File

@ -1,5 +1,8 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, plusplus: true */
/*global _, require, db, exports */
var Frank,
baseMiddleware,
BaseMiddleware,
_ = require("underscore"),
internal = {};
@ -37,7 +40,8 @@ Frank = function (options) {
}
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) {
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";
}
template = templateCollection.firstExample({path: "simple/path"});
template = templateCollection.firstExample({path: templatePath });
if (_.isNull(template)) {
throw "Template '" + templatePath + "' does not exist";
}
if (template.templateLanguage !== "underscore") {
throw "Unknown template language '" + template.templateLanguage + "'";
@ -137,6 +145,8 @@ BaseMiddleware = function (templateCollection) {
};
response = _.extend(response, responseFunctions);
next();
};
return middleware;

View File

@ -243,6 +243,18 @@ function BaseMiddlewareWithoutTemplateSpec () {
}
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'");
},
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(SetRoutesFrankSpec);
jsunity.run(BaseMiddlewareWithoutTemplateSpec);