Browse Source

checking for existence of del() method before binding to it

feature/nested-cache-fetch-fix
Bryan Donovan 11 years ago
parent
commit
d38e274a30
  1. 4
      lib/caching.js
  2. 17
      test/caching.unit.js

4
lib/caching.js

@ -1,4 +1,4 @@
/*jshint maxcomplexity:10*/ /*jshint maxcomplexity:15*/
var caching = function (args) { var caching = function (args) {
args = args || {}; args = args || {};
var self = {}; var self = {};
@ -78,7 +78,9 @@ var caching = function (args) {
self.set = self.store.set.bind(self.store); self.set = self.store.set.bind(self.store);
if (typeof self.store.del === 'function') {
self.del = self.store.del.bind(self.store); self.del = self.store.del.bind(self.store);
}
if (typeof self.store.setex === 'function') { if (typeof self.store.setex === 'function') {
self.setex = self.store.setex.bind(self.store); self.setex = self.store.setex.bind(self.store);

17
test/caching.unit.js

@ -145,6 +145,23 @@ describe("caching", function () {
}); });
}, 10); }, 10);
}); });
context("when store has no del() method", function () {
var fake_store;
beforeEach(function () {
fake_store = {
get: function () {},
set: function () {},
};
});
it("it doesn't throw an error", function () {
assert.doesNotThrow(function () {
caching({store: fake_store});
});
});
});
}); });
describe("setex()", function () { describe("setex()", function () {

Loading…
Cancel
Save