Skip to content
Myr

spec.plugins.cache.js

This file

Path

spec/spec.plugins.cache.js

110 lines · 2.8 KiB · JavaScript

Last changed by

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

History of this file

Take it

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 1–110why, one step back
1
2describe 'Express'3 before_each4 reset()5 use(require('express/plugins/cache').Cache)6 cache = require('express/plugins/cache')7 end8 9 describe 'Cache'10 describe 'Request'11 describe '#cache'12 it 'should use memory store by default'13 get('/item', function(){14 return this.cache.toString()15 })16 get('/item').body.should.eql '[Memory Store]'17 end18 end19 end20 end21 22 describe 'Store'23 describe 'Memory'24 before_each25 store = new cache.Store.Memory26 end27 28 describe '#toString()'29 it 'should return [Memory Store]'30 store.toString().should.eql '[Memory Store]'31 end32 end33 34 describe '#set()'35 describe 'given a key and value'36 it 'should set the cache data'37 store.set('foo', 'bar')38 store.get('foo').should.eql 'bar'39 end40 41 it 'should override existing data'42 store.set('foo', 'bar')43 store.set('foo', 'baz')44 store.get('foo').should.eql 'baz'45 end46 47 it 'should return data'48 store.set('foo', 'bar').should.eql 'bar'49 end50 end51 52 describe 'given an abitrary key'53 it 'should throw an error'54 -{ store.set({}, 'foo') }.should.throw_error55 end56 end57 58 describe 'given an abitrary value'59 it 'should serialize as JSON'60 store.set('user', { name: 'tj' }).should.eql { name: 'tj' }61 end62 end63 end64 65 describe '#get()'66 describe 'given a key'67 it 'should return cached value'68 store.set('foo', 'bar')69 store.get('foo').should.eql 'bar'70 end71 72 it 'should unserialize JSON data'73 store.set('user', { name: 'tj' })74 store.get('user').should.eql { name: 'tj' }75 end76 end77 78 describe 'given wildcards'79 it 'should return a set of caches'80 store.set('user:1', 'a')81 store.set('user:2', 'b')82 store.set('foo', 'bar')83 store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' }84 end85 end86 end87 88 describe '#clear()'89 describe 'given a key'90 it 'should delete previous data'91 store.set('foo', 'bar')92 store.clear('foo')93 store.get('foo').should.be_null94 end95 end96 97 describe 'given wildcards'98 it 'should clear a set of caches'99 store.set('user:one', '1')100 store.set('user:two', '2')101 store.clear('user:*')102 store.get('user:one').should.be_null103 store.get('user:two').should.be_null104 end105 end106 end107 108 end109 end110end