Skip to content

Commit

Permalink
adding clear() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Carson committed Aug 21, 2013
1 parent c0c20e6 commit c3022ca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
7 changes: 6 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
0.0.2 / 2013-08-20
0.0.4 / 2013-08-20
==================

* Add clear()

0.0.3 / 2013-08-20
==================

* Fixes to session id characters, use Firebase.once() instead of Firebase.on() for get()
Expand Down
14 changes: 14 additions & 0 deletions lib/connect-firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ module.exports = function (connect) {
sessionRef.remove(fn);

};

/**
* Clear all sessions.
*
* @param {Function} fn
* @api public
*/

FirebaseStore.prototype.clear = function (fn) {

var sessionRef = new Firebase('https://' + this.firebase_url + '/sessions');
sessionRef.remove(fn);

};

return FirebaseStore;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "connect-firebase",
"description": "Firebase session store for Connect",
"version": "0.0.3",
"version": "0.0.4",
"author": "Mike Carson <[email protected]> (http://ca98am79.com)",
"main": "./index.js",
"dependencies": {
Expand Down
41 changes: 41 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,45 @@ describe('FirebaseStore', function () {
});

});
describe('Clearing', function () {
before(function () {
var store = new FirebaseStore({
firebase_url: firebase_url
});
store.set('abcd', {
cookie: {
maxAge: 2000
},
name: 'tj'
}, function () {});
store.set('abcdef', {
cookie: {
maxAge: 2000
},
name: 'tj'
}, function () {});
});

it('should clear sessions correctly', function (done) {
var store = new FirebaseStore({
firebase_url: firebase_url
});
store.clear(function (err, res) {
if (err) throw err;

store.get('abcd', function (err, res) {
if (err) throw err;
should.not.exist(res);

store.get('abcdef', function (err, res) {
if (err) throw err;
should.not.exist(res);

done();
});
});
});
});

});
});

0 comments on commit c3022ca

Please sign in to comment.