@@ -5,7 +5,6 @@ var assert = require('assert');
55
66var redisCache ;
77var customRedisCache ;
8- var customRedisCache2 ;
98
109before ( function ( ) {
1110 redisCache = require ( 'cache-manager' ) . caching ( {
@@ -25,20 +24,11 @@ before(function () {
2524 ttl : config . redis . ttl ,
2625 isCacheableValue : function ( val ) {
2726 // allow undefined
28- if ( val === undefined ) return true ;
29- return redisCache . store . isCacheableValue ( val ) ;
30- }
31- } ) ;
32-
33- customRedisCache2 = require ( 'cache-manager' ) . caching ( {
34- store : redisStore ,
35- host : config . redis . host ,
36- port : config . redis . port ,
37- db : config . redis . db ,
38- ttl : config . redis . ttl ,
39- isCacheableValue : function ( val ) {
27+ if ( val === undefined )
28+ return true ;
4029 // disallow FooBarString
41- if ( val === 'FooBarString' ) return false ;
30+ else if ( val === 'FooBarString' )
31+ return false ;
4232 return redisCache . store . isCacheableValue ( val ) ;
4333 }
4434 } ) ;
@@ -92,20 +82,20 @@ describe('set', function () {
9282 done ( ) ;
9383 } ) ;
9484 } ) ;
85+ } ) ;
9586
96- it ( 'should store a null value without error' , function ( done ) {
97- redisCache . set ( 'foo2' , null , function ( err ) {
98- try {
87+ it ( 'should store a null value without error' , function ( done ) {
88+ redisCache . set ( 'foo2' , null , function ( err ) {
89+ try {
90+ assert . equal ( err , null ) ;
91+ redisCache . get ( 'foo2' , function ( err , value ) {
9992 assert . equal ( err , null ) ;
100- redisCache . get ( 'foo2' , function ( err , value ) {
101- assert . equal ( err , null ) ;
102- assert . equal ( value , null ) ;
103- done ( ) ;
104- } ) ;
105- } catch ( e ) {
106- done ( e ) ;
107- }
108- } ) ;
93+ assert . equal ( value , null ) ;
94+ done ( ) ;
95+ } ) ;
96+ } catch ( e ) {
97+ done ( e ) ;
98+ }
10999 } ) ;
110100 } ) ;
111101
@@ -130,7 +120,7 @@ describe('set', function () {
130120 } ) ;
131121 } ) ;
132122
133- it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
123+ it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
134124 assert ( customRedisCache . store . isCacheableValue ( undefined ) , true ) ;
135125 customRedisCache . set ( 'foo3' , undefined , function ( err ) {
136126 try {
@@ -152,8 +142,8 @@ describe('set', function () {
152142 } ) ;
153143
154144 it ( 'should not store a value disallowed by isCacheableValue' , function ( done ) {
155- assert . strictEqual ( customRedisCache2 . store . isCacheableValue ( 'FooBarString' ) , false ) ;
156- customRedisCache2 . set ( 'foobar' , 'FooBarString' , function ( err ) {
145+ assert . strictEqual ( customRedisCache . store . isCacheableValue ( 'FooBarString' ) , false ) ;
146+ customRedisCache . set ( 'foobar' , 'FooBarString' , function ( err ) {
157147 try {
158148 assert . notEqual ( err , null ) ;
159149 assert . equal ( err . message , 'value cannot be FooBarString' ) ;
@@ -199,10 +189,10 @@ describe('get', function () {
199189
200190 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
201191 var pool = redisCache . store . _pool ;
202- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
192+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
203193 sinon . stub ( pool , 'release' ) ;
204194 redisCache . get ( 'foo' , function ( err ) {
205- pool . acquire . restore ( ) ;
195+ pool . acquireDb . restore ( ) ;
206196 pool . release . restore ( ) ;
207197 assert . notEqual ( err , null ) ;
208198 done ( ) ;
@@ -229,11 +219,11 @@ describe('del', function () {
229219
230220 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
231221 var pool = redisCache . store . _pool ;
232- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
222+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
233223 sinon . stub ( pool , 'release' ) ;
234224 redisCache . set ( 'foo' , 'bar' , function ( ) {
235225 redisCache . del ( 'foo' , function ( err ) {
236- pool . acquire . restore ( ) ;
226+ pool . acquireDb . restore ( ) ;
237227 pool . release . restore ( ) ;
238228 assert . notEqual ( err , null ) ;
239229 done ( ) ;
@@ -257,10 +247,10 @@ describe('reset', function () {
257247
258248 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
259249 var pool = redisCache . store . _pool ;
260- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
250+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
261251 sinon . stub ( pool , 'release' ) ;
262252 redisCache . reset ( function ( err ) {
263- pool . acquire . restore ( ) ;
253+ pool . acquireDb . restore ( ) ;
264254 pool . release . restore ( ) ;
265255 assert . notEqual ( err , null ) ;
266256 done ( ) ;
@@ -289,11 +279,11 @@ describe('ttl', function () {
289279
290280 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
291281 var pool = redisCache . store . _pool ;
292- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
282+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
293283 sinon . stub ( pool , 'release' ) ;
294284 redisCache . set ( 'foo' , 'bar' , function ( ) {
295285 redisCache . ttl ( 'foo' , function ( err ) {
296- pool . acquire . restore ( ) ;
286+ pool . acquireDb . restore ( ) ;
297287 pool . release . restore ( ) ;
298288 assert . notEqual ( err , null ) ;
299289 done ( ) ;
@@ -327,11 +317,11 @@ describe('keys', function () {
327317
328318 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
329319 var pool = redisCache . store . _pool ;
330- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
320+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
331321 sinon . stub ( pool , 'release' ) ;
332322 redisCache . set ( 'foo' , 'bar' , function ( ) {
333323 redisCache . keys ( 'f*' , function ( err ) {
334- pool . acquire . restore ( ) ;
324+ pool . acquireDb . restore ( ) ;
335325 pool . release . restore ( ) ;
336326 assert . notEqual ( err , null ) ;
337327 done ( ) ;
@@ -341,16 +331,16 @@ describe('keys', function () {
341331} ) ;
342332
343333describe ( 'isCacheableValue' , function ( ) {
344- it ( 'should return true when the value is not null or undefined' , function ( done ) {
334+ it ( 'should return true when the value is not undefined' , function ( done ) {
345335 assert . equal ( redisCache . store . isCacheableValue ( 0 ) , true ) ;
346336 assert . equal ( redisCache . store . isCacheableValue ( 100 ) , true ) ;
347337 assert . equal ( redisCache . store . isCacheableValue ( '' ) , true ) ;
348338 assert . equal ( redisCache . store . isCacheableValue ( 'test' ) , true ) ;
339+ assert . equal ( redisCache . store . isCacheableValue ( null ) , true ) ;
349340 done ( ) ;
350341 } ) ;
351342
352- it ( 'should return false when the value is null or undefined' , function ( done ) {
353- assert . equal ( redisCache . store . isCacheableValue ( null ) , false ) ;
343+ it ( 'should return false when the value is undefined' , function ( done ) {
354344 assert . equal ( redisCache . store . isCacheableValue ( undefined ) , false ) ;
355345 done ( ) ;
356346 } ) ;
@@ -378,10 +368,10 @@ describe('getClient', function () {
378368
379369 it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
380370 var pool = redisCache . store . _pool ;
381- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
371+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
382372 sinon . stub ( pool , 'release' ) ;
383373 redisCache . store . getClient ( function ( err ) {
384- pool . acquire . restore ( ) ;
374+ pool . acquireDb . restore ( ) ;
385375 pool . release . restore ( ) ;
386376 assert . notEqual ( err , null ) ;
387377 done ( ) ;
0 commit comments