Skip to content
Myr

spec.plugins.cache.js

This file

Path

spec/spec.plugins.cache.js

107 lines · 2.8 KiB · JavaScript

Last changed by

Added normalize()visionmediabefore adoption965cbf6

History of this file

Take it

Started caching apivisionmediabefore adoptionc161750

lines 1–4why, one step back
1
2describe 'Express'3 before_each4 reset()

Started Store.Memory specsvisionmediabefore adoptiona82b1b9

lines 5–6why, one step back
5 use(require('express/plugins/cache').Cache)
6 cache = require('express/plugins/cache')

Started caching apivisionmediabefore adoptionc161750

lines 7–16why, one step back
7 end
8 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]'

Started Store.Memory specsvisionmediabefore adoptiona82b1b9

lines 17–23why, one step back
17 end
18 end19 end20 end21 22 describe 'Store'23 describe 'Memory'

Added memory store specsvisionmediabefore adoptionf2d08aa

lines 24–27why, one step back
24 before_each
25 store = new cache.Store.Memory26 end27

Started Store.Memory specsvisionmediabefore adoptiona82b1b9

lines 28–29why, one step back
28 describe '#toString()'
29 it 'should return [Memory Store]'

Added memory store specsvisionmediabefore adoptionf2d08aa

line 30why, one step back
30 store.toString().should.eql '[Memory Store]'

Started caching apivisionmediabefore adoptionc161750

lines 31–32why, one step back
31 end
32 end

Added memory store specsvisionmediabefore adoptionf2d08aa

lines 33–45why, one step back
33
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 end

Started implemented cache methodsvisionmediabefore adoptiond4d76cd

lines 46–48why, one step back
46
47 it 'should return data'48 store.set('foo', 'bar').should.eql 'bar'

Added memory store specsvisionmediabefore adoptionf2d08aa

lines 49–59why, one step back
49 end
50 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 throw an error'

Started implemented cache methodsvisionmediabefore adoptiond4d76cd

lines 60–61why, one step back
60 -{ store.set('foo', null) }.should.throw_error
61 -{ store.set('foo', undefined) }.should.throw_error

Added memory store specsvisionmediabefore adoptionf2d08aa

lines 62–104why, one step back
62 -{ store.set('foo', {}) }.should.throw_error
63 end64 end65 end66 67 describe '#get()'68 describe 'given a key'69 it 'should return cached value'70 store.set('foo', 'bar')71 store.get('foo').should.eql 'bar'72 end73 end74 75 describe 'given wildcards'76 it 'should return a set of caches'77 store.set('user:1', 'a')78 store.set('user:2', 'b')79 store.set('foo', 'bar')80 store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' }81 end82 end83 end84 85 describe '#clear()'86 describe 'given a key'87 it 'should delete previous data'88 store.set('foo', 'bar')89 store.clear('foo')90 store.get('foo').should.be_null91 end92 end93 94 describe 'given wildcards'95 it 'should clear a set of caches'96 store.set('user:one', '1')97 store.set('user:two', '2')98 store.clear('user:*')99 store.get('user:one').should.be_null100 store.get('user:two').should.be_null101 end102 end103 end104

Started caching apivisionmediabefore adoptionc161750

lines 105–107why, one step back
105 end
106 end107end