From 275bcb00f4fcb3bd1446b0f4b450f8535d23baf8 Mon Sep 17 00:00:00 2001 From: Bryan Donovan Date: Mon, 8 Apr 2013 15:51:24 -0700 Subject: [PATCH] testing that we can pass in a a store module --- lib/caching.js | 6 +++++- test/caching.unit.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/caching.js b/lib/caching.js index 620989b..775ffe4 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -2,7 +2,11 @@ var caching = function (args) { args = args || {}; var self = {}; if (typeof args.store === 'object') { - self.store = args.store; + if (args.store.create) { + self.store = args.store.create(args); + } else { + self.store = args.store; + } } else if (typeof args.store === 'string' && args.store.match(/\//)) { self.store = require(args.store).create(args); } else { diff --git a/test/caching.unit.js b/test/caching.unit.js index e185fbe..df6e038 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -348,5 +348,17 @@ describe("caching", function () { }); }); }); + + it("allows us to pass in a module (uninstantiated)", function (done) { + var store = memory_store; + cache = caching({store: store}); + cache.set(key, value, function (err) { + check_err(err); + cache.get(key, function (err, result) { + assert.equal(result, value); + done(); + }); + }); + }); }); });