spec.plugins.cache.js
This file
Path
spec/spec.plugins.cache.js
171 lines · 4.5 KiB · JavaScript
Last changed by
Added more cache key specsvisionmediabefore adoption2bcea3a
History of this fileTake it
The walk stopped after 200 commits: lines older than 7cf9c68 point at it.
Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 1–35why, one step back12describe '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 'cache Store.Memory'23 before_each24 store = new cache.Store.Memory25 end26 27 describe '#toString()'28 it 'should return [Memory Store]'29 store.toString().should.eql '[Memory Store]'30 end31 end32 33 describe '#set()'34 describe 'given a key and value'35 it 'should set the cache data'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 36–42why, one step back36 var result37 store.set('foo', 'bar', function(){38 store.get('foo', function(val){39 result = val40 })41 })42 result.should.eql 'bar'Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 43–44why, one step back43 end44 Added more cache key specsvisionmediabefore adoption2bcea3a
lines 45–59why, one step back45 it 'should work with regexp special characters'46 var result,47 result248 store.set('page:/users/1/comments?page=2', 'html', function(){49 store.get('page:/users/1/comments?page=2', function(val){50 result = val51 store.get('page:*', function(vals){52 result2 = vals53 })54 })55 })56 result.should.eql 'html'57 result2.should.eql { 'page:/users/1/comments?page=2': 'html' }58 end59 Merge branch 'fix-views'visionmediabefore adoption7cf9c68
line 60why, one step back60 it 'should override existing data'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 61–69why, one step back61 var result62 store.set('foo', 'bar', function(){63 store.set('foo', 'baz', function(){64 store.get('foo', function(val){65 result = val66 })67 })68 })69 result.should.eql 'baz'Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 70–80why, one step back70 end71 end72 73 describe 'given an abitrary key'74 it 'should throw an error'75 -{ store.set({}, 'foo') }.should.throw_error76 end77 end78 79 describe 'given an abitrary value'80 it 'should serialize as JSON'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 81–85why, one step back81 var result82 store.set('user', { name: 'tj' }, function(val){83 result = val84 })85 result.should.eql { name: 'tj' }Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 86–92why, one step back86 end87 end88 end89 90 describe '#get()'91 describe 'given a key'92 it 'should unserialize JSON data'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 93–99why, one step back93 var result94 store.set('user', { name: 'tj' }, function(){95 store.get('user', function(val){96 result = val97 })98 })99 result.should.eql { name: 'tj' }Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 100–103why, one step back100 end101 end102 103 describe 'given wildcards'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 104–115why, one step back104 it 'should pass a set of caches'105 var result106 store.set('user:1', 'a', function(){107 store.set('user:2', 'b', function(){108 store.set('foo', 'bar', function(){109 store.get('user:*', function(val){110 result = val111 })112 })113 })114 })115 result.should.eql { 'user:1': 'a', 'user:2': 'b' }Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 116–122why, one step back116 end117 end118 end119 120 describe '#clear()'121 describe 'given a key'122 it 'should delete previous data'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 123–131why, one step back123 var result124 store.set('foo', 'bar', function(){125 store.clear('foo', function(){126 store.get('foo', function(val){127 result = val128 })129 })130 })131 result.should.be_nullMerge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 132–136why, one step back132 end133 end134 135 describe 'given wildcards'136 it 'should clear a set of caches'Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 137–150why, one step back137 var results = []138 store.set('user:one', '1', function(){139 store.set('user:two', '2', function(){140 store.clear('user:*', function(){141 store.get('user:one', function(val){142 results.push(val)143 store.get('user:two', function(val){144 results.push(val)145 })146 })147 })148 }) 149 })150 results.should.eql [null, null]Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 151–157why, one step back151 end152 end153 end154 155 describe '#reap()'156 it 'should destroy caches older than the given age in milliseconds'157 store.set('user:one', '1')Merge branch 'async-cache'visionmediabefore adoption7606f1b
line 158why, one step back158 store.data['user:one'].created = Number((5).minutes.ago)Merge branch 'fix-views'visionmediabefore adoption7cf9c68
line 159why, one step back159 store.set('user:two', '2')Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 160–167why, one step back160 store.data['user:two'].created = Number((2).seconds.ago)161 store.reap((1).minute)162 store.get('user:one', function(val){163 val.should.be_null164 })165 store.get('user:two', function(val){166 val.should.not.be_null167 })Merge branch 'fix-views'visionmediabefore adoption7cf9c68
lines 168–171why, one step back168 end169 end170 end171end