From 844e664cb5281c81336a998f112917402eb04d06 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Mon, 28 Nov 2011 20:49:12 -0500 Subject: [PATCH] Added some tests for redis document store --- TODO.md | 5 -- spec/redis_document_store_spec.js | 78 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 spec/redis_document_store_spec.js diff --git a/TODO.md b/TODO.md index 46703c6..46a7e2b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,2 @@ -# TODO for OSS -* tests * Add file extensions ourselves to push state * add feedback for errors to UI - esp. too long - -# shared version only -* some way to do announcements easily (and use for ads) diff --git a/spec/redis_document_store_spec.js b/spec/redis_document_store_spec.js new file mode 100644 index 0000000..d96bd60 --- /dev/null +++ b/spec/redis_document_store_spec.js @@ -0,0 +1,78 @@ +var RedisDocumentStore = require('../lib/redis_document_store'); + +describe('redis_document_store', function() { + + describe('set', function() { + + it('should be able to set a key and have an expiration set', function() { + var store = new RedisDocumentStore({ expire: 10 }); + runs(function() { + var _this = this; + store.set('hello1', 'world', function(worked) { + _this.result = worked; + }); + }); + waitsFor(function() { + return typeof(this.result) === 'boolean'; + }); + runs(function() { + var _this = this; + RedisDocumentStore.client.ttl('hello1', function(err, res) { + expect(res).toBeGreaterThan(1); + _this.done = true; + }); + }); + waitsFor(function() { + return this.done; + }); + }); + + it('should not set an expiration when told not to', function() { + var store = new RedisDocumentStore({ expire: 10 }); + runs(function() { + var _this = this; + store.set('hello2', 'world', function(worked) { + _this.result = worked; + }, true); + }); + waitsFor(function() { + return typeof(this.result) === 'boolean'; + }); + runs(function() { + var _this = this; + RedisDocumentStore.client.ttl('hello2', function(err, res) { + expect(res).toBe(-1); + _this.done = true; + }); + }); + waitsFor(function() { + return this.done; + }); + }); + + it('should not set an expiration when expiration is off', function() { + var store = new RedisDocumentStore({ expire: false }); + runs(function() { + var _this = this; + store.set('hello3', 'world', function(worked) { + _this.result = worked; + }); + }); + waitsFor(function() { + return typeof(this.result) === 'boolean'; + }); + runs(function() { + var _this = this; + RedisDocumentStore.client.ttl('hello3', function(err, res) { + expect(res).toBe(-1); + _this.done = true; + }); + }); + waitsFor(function() { + return this.done; + }); + }); + + }); + +});