@@ -7,98 +7,98 @@ var Concoction = require('concoction');
7
7
var EventEmitter = require ( 'events' ) . EventEmitter ;
8
8
9
9
function EventEmitterCache ( ) {
10
- this . cache = { } ;
10
+ this . cache = { } ;
11
11
}
12
12
13
13
EventEmitterCache . prototype . __proto__ = EventEmitter . prototype ;
14
14
EventEmitterCache . prototype . valid = function ( conditions ) {
15
- return conditions && conditions . _id ;
15
+ return conditions && conditions . _id ;
16
16
} ;
17
17
EventEmitterCache . prototype . store = function ( conditions , document , callback ) {
18
- this . emit ( 'store' ) ;
19
- var id = JSON . stringify ( document . _id ) ;
20
- this . cache [ id ] = document ;
21
- callback ( ) ;
18
+ this . emit ( 'store' ) ;
19
+ var id = JSON . stringify ( document . _id ) ;
20
+ this . cache [ id ] = document ;
21
+ callback ( ) ;
22
22
} ;
23
23
EventEmitterCache . prototype . fetch = function ( document , callback ) {
24
- var id = JSON . stringify ( document . _id ) ;
25
- if ( this . cache [ id ] ) this . emit ( 'fetched' ) ;
26
- callback ( this . cache [ id ] ) ;
24
+ var id = JSON . stringify ( document . _id ) ;
25
+ if ( this . cache [ id ] ) this . emit ( 'fetched' ) ;
26
+ callback ( this . cache [ id ] ) ;
27
27
} ;
28
28
EventEmitterCache . prototype . drop = function ( document , callback ) {
29
- var id = JSON . stringify ( document . _id ) ;
30
- if ( this . cache [ id ] ) {
31
- delete this . cache [ id ] ;
32
- this . emit ( 'dropped' ) ;
33
- }
34
- callback ( ) ;
29
+ var id = JSON . stringify ( document . _id ) ;
30
+ if ( this . cache [ id ] ) {
31
+ delete this . cache [ id ] ;
32
+ this . emit ( 'dropped' ) ;
33
+ }
34
+ callback ( ) ;
35
35
} ;
36
36
37
37
describe ( 'orm' , function ( ) {
38
- "use strict" ;
38
+ "use strict" ;
39
39
40
- describe ( 'Model' , function ( ) {
41
- var db = null ;
40
+ describe ( 'Model' , function ( ) {
41
+ var db = null ;
42
42
43
- before ( function ( done ) {
44
- db = new Database ( config ) ;
45
- db . connect ( done ) ;
46
- } ) ;
43
+ before ( function ( done ) {
44
+ db = new Database ( config ) ;
45
+ db . connect ( done ) ;
46
+ } ) ;
47
47
48
- describe ( 'cache' , function ( ) {
49
- var model = null ;
48
+ describe ( 'cache' , function ( ) {
49
+ var model = null ;
50
50
51
- before ( function ( done ) {
52
- model = new Model ( db , 'model' , {
53
- name : / .+ /
54
- } , {
55
- preprocessors : [ new Concoction . Rename ( { _id : 'name' } ) ] ,
56
- cache : new EventEmitterCache ( )
57
- } ) ;
51
+ before ( function ( done ) {
52
+ model = new Model ( db , 'model' , {
53
+ name : / .+ /
54
+ } , {
55
+ preprocessors : [ new Concoction . Rename ( { _id : 'name' } ) ] ,
56
+ cache : new EventEmitterCache ( )
57
+ } ) ;
58
58
59
- model . remove ( function ( err ) {
60
- if ( err ) return done ( err ) ;
59
+ model . remove ( function ( err ) {
60
+ if ( err ) return done ( err ) ;
61
61
62
- model . create ( {
63
- name : 'Demo1'
64
- } , function ( err , instance ) {
65
- if ( err ) return done ( err ) ;
66
- return done ( ) ;
67
- } ) ;
68
- } ) ;
69
- } ) ;
62
+ model . create ( {
63
+ name : 'Demo1'
64
+ } , function ( err , instance ) {
65
+ if ( err ) return done ( err ) ;
66
+ return done ( ) ;
67
+ } ) ;
68
+ } ) ;
69
+ } ) ;
70
70
71
- describe ( 'findOne' , function ( ) {
72
- it ( 'should store newly retrieved documents in the cache' , function ( done ) {
73
- var pending = 2 ;
74
- function almostDone ( ) {
75
- if ( ! ( -- pending ) ) return done ( ) ;
76
- }
71
+ describe ( 'findOne' , function ( ) {
72
+ it ( 'should store newly retrieved documents in the cache' , function ( done ) {
73
+ var pending = 2 ;
74
+ function almostDone ( ) {
75
+ if ( ! ( -- pending ) ) return done ( ) ;
76
+ }
77
77
78
- model . cache . once ( 'store' , almostDone ) ;
78
+ model . cache . once ( 'store' , almostDone ) ;
79
79
80
- model . findOne ( 'Demo1' , function ( err , instance ) {
81
- should . not . exist ( err ) ;
82
- should . exist ( instance ) ;
83
- almostDone ( ) ;
84
- } ) ;
85
- } ) ;
80
+ model . findOne ( 'Demo1' , function ( err , instance ) {
81
+ should . not . exist ( err ) ;
82
+ should . exist ( instance ) ;
83
+ almostDone ( ) ;
84
+ } ) ;
85
+ } ) ;
86
86
87
- it ( 'should fetch retrieved documents from the cache' , function ( done ) {
88
- var pending = 2 ;
89
- function almostDone ( ) {
90
- if ( ! ( -- pending ) ) return done ( ) ;
91
- }
87
+ it ( 'should fetch retrieved documents from the cache' , function ( done ) {
88
+ var pending = 2 ;
89
+ function almostDone ( ) {
90
+ if ( ! ( -- pending ) ) return done ( ) ;
91
+ }
92
92
93
- model . cache . once ( 'fetched' , almostDone ) ;
93
+ model . cache . once ( 'fetched' , almostDone ) ;
94
94
95
- model . findOne ( 'Demo1' , function ( err , instance ) {
96
- should . not . exist ( err ) ;
97
- should . exist ( instance ) ;
98
- almostDone ( ) ;
99
- } ) ;
100
- } ) ;
101
- } ) ;
102
- } ) ;
103
- } ) ;
95
+ model . findOne ( 'Demo1' , function ( err , instance ) {
96
+ should . not . exist ( err ) ;
97
+ should . exist ( instance ) ;
98
+ almostDone ( ) ;
99
+ } ) ;
100
+ } ) ;
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
104
104
} ) ;
0 commit comments