Permalink
Browse files

handle null request basenames on cahce store

  • Loading branch information...
1 parent 1e2ffb6 commit e11539c81459d3b2a4ba24ba2bd5a7721605ea04 @laktek committed Mar 17, 2013
Showing with 35 additions and 0 deletions.
  1. +14 −0 lib/cache_store.js
  2. +21 −0 spec/cache_store.spec.js
View
@@ -22,6 +22,10 @@ module.exports = {
stat: function(request_basename, file_extension, request_options, callback) {
var self = this;
+ if(!request_basename) {
+ return callback("request basename can't be null");
+ }
+
if (self.templates.isSection(request_basename) || self.contents.isSection(request_basename)) {
request_basename = path.join(request_basename, "index");
}
@@ -39,6 +43,11 @@ module.exports = {
get: function(request_basename, file_extension, rendered_obj, request_options, callback){
var self = this;
+
+ if(!request_basename) {
+ return callback("request basename can't be null");
+ }
+
var header = (rendered_obj.options && rendered_obj.options.header) || {};
var cache_obj = {"body": null, "options": {"header": header}};
var encoding = (file_extension === ".html") ? "utf8" : "binary";
@@ -68,6 +77,11 @@ module.exports = {
update: function(request_basename, file_extension, rendered_obj, request_options, callback){
var self = this;
+
+ if(!request_basename) {
+ return callback("request basename can't be null");
+ }
+
var body = rendered_obj.body;
var header = (rendered_obj.options && rendered_obj.options.header) || {};
var encoding = (file_extension === ".html") ? "utf8" : "binary";
@@ -40,6 +40,13 @@ describe("setup", function(){
describe("stat", function(){
+ it("call the callback with an error if request basename is null", function(){
+ var spyCallback = jasmine.createSpy();
+ cache_store.stat(null, ".html", {}, spyCallback);
+
+ expect(spyCallback).toHaveBeenCalledWith("request basename can't be null");
+ });
+
it("call the callback with the file's modified time", function(){
var spyIsSection = jasmine.createSpy();
spyIsSection.andReturn(false);
@@ -85,6 +92,13 @@ describe("stat", function(){
describe("get", function(){
+ it("call the callback with an error if request basename is null", function(){
+ var spyCallback = jasmine.createSpy();
+ cache_store.get(null, ".html", { "options": {} }, {}, spyCallback);
+
+ expect(spyCallback).toHaveBeenCalledWith("request basename can't be null");
+ });
+
it("correct the given path if it's a section", function() {
var spyIsSection = jasmine.createSpy();
spyIsSection.andReturn(true);
@@ -177,6 +191,13 @@ describe("get", function(){
describe("update", function(){
+ it("call the callback with an error if request basename is null", function(){
+ var spyCallback = jasmine.createSpy();
+ cache_store.update(null, ".html", { "body": "test", "options": { "header": {} } }, {}, spyCallback);
+
+ expect(spyCallback).toHaveBeenCalledWith("request basename can't be null");
+ });
+
it("create missing directories", function(){
var spyIsSection = jasmine.createSpy();
spyIsSection.andReturn(false);

0 comments on commit e11539c

Please sign in to comment.