Skip to content

Commit

Permalink
Fix for issue #44/#42
Browse files Browse the repository at this point in the history
  • Loading branch information
mhinton committed Aug 25, 2015
1 parent 4985edb commit 1304beb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/persistent_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ PersistentSession.prototype.clear = function _psClear(key, list) {
self.set(akey, undefined, false, false);

changed(self._dict.keyDeps[akey]);
changed(self._dict.keyValueDeps[akey][value]);
changed(self._dict.keyValueDeps[akey]['undefined']);
if (self._dict.keyValueDeps[akey]) {
changed(self._dict.keyValueDeps[akey][value]);
changed(self._dict.keyValueDeps[akey]['undefined']);
}

delete self._dict.keys[akey]; // remove the key
});
Expand Down
13 changes: 13 additions & 0 deletions tests/client/persistent_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ Tinytest.add("clear all keys", function(test) {
test.equal(undefined, result);
});

Tinytest.add("skip undefined keys", function(test) {
var TestSession = new PersistentSession(Random.id());
test.equal(_.keys(TestSession._dict.keys).length, 0);

TestSession.set(undefined, 'woo');
test.equal(_.keys(TestSession._dict.keys).length, 1);

TestSession.clear();

test.equal(_.keys(TestSession._dict.keys).length, 0);

});

Tinytest.add("clear single key", function(test) {
var TestSession = new PersistentSession(Random.id());

Expand Down

0 comments on commit 1304beb

Please sign in to comment.