Async cache specs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 273a51a · Browse files · 1 file·+63 added−30 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+63 added−30 removed
- tests:+63 added−30 removed
Provenance
- Commit
b92f1b7- Tree
4358744- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
273a51a
1 file changed+63 added−30 removed
modified:spec/spec.plugins.cache.js+63 added-30 removed
31 unmodified lines323334353637363738394041424344454142434647484950515253545545464748565758592 unmodified lines626364656659676869707172737475766667686970777273787980818283848586878878798081828990919293949596979899100101102103104105106107909192108109110111112113114115116117118119120121989910010110212212312412512612712812913013113213313413513613713813913 unmodified lines31 unmodified lines describe '#set()' describe 'given a key and value' it 'should set the cache data' store.set('foo', 'bar') store.get('foo').should.eql 'bar' var result store.set('foo', 'bar', function(){ store.get('foo', function(val){ result = val }) }) result.should.eql 'bar' end it 'should override existing data' store.set('foo', 'bar') store.set('foo', 'baz') store.get('foo').should.eql 'baz' var result store.set('foo', 'bar', function(){ store.set('foo', 'baz', function(){ store.get('foo', function(val){ result = val }) }) }) result.should.eql 'baz' end it 'should return data' store.set('foo', 'bar').should.eql 'bar' end end describe 'given an abitrary key' it 'should throw an error'2 unmodified lines end describe 'given an abitrary value' it 'should serialize as JSON' var result store.set('user', { name: 'tj' }).should.eql { name: 'tj' } store.set('user', { name: 'tj' }, function(val){ result = val }) result.should.eql { name: 'tj' } end end end describe '#get()' describe 'given a key' it 'should return cached value' store.set('foo', 'bar') store.get('foo').should.eql 'bar' end it 'should unserialize JSON data' store.set('user', { name: 'tj' }) store.get('user').should.eql { name: 'tj' } var result store.set('user', { name: 'tj' }, function(){ store.get('user', function(val){ result = val }) }) result.should.eql { name: 'tj' } end end describe 'given wildcards' it 'should return a set of caches' store.set('user:1', 'a') store.set('user:2', 'b') store.set('foo', 'bar') store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' } it 'should pass a set of caches' var result store.set('user:1', 'a', function(){ store.set('user:2', 'b', function(){ store.set('foo', 'bar', function(){ store.get('user:*', function(val){ result = val }) }) }) }) result.should.eql { 'user:1': 'a', 'user:2': 'b' } end end end describe '#clear()' describe 'given a key' it 'should delete previous data' store.set('foo', 'bar') store.clear('foo') store.get('foo').should.be_null var result store.set('foo', 'bar', function(){ store.clear('foo', function(){ store.get('foo', function(val){ result = val }) }) }) result.should.be_null end end describe 'given wildcards' it 'should clear a set of caches' store.set('user:one', '1') store.set('user:two', '2') store.clear('user:*') store.get('user:one').should.be_null store.get('user:two').should.be_null var results = [] store.set('user:one', '1', function(){ store.set('user:two', '2', function(){ store.clear('user:*', function(){ store.get('user:one', function(val){ results.push(val) store.get('user:two', function(val){ results.push(val) }) }) }) }) }) results.should.eql [null, nukk] end end end 13 unmodified lines