@@ -3,8 +3,9 @@ var helper = require('../support/spec_helper');
3
3
var ORM = require ( '../../' ) ;
4
4
5
5
describe ( "Model.get()" , function ( ) {
6
- var db = null ;
6
+ var db = null ;
7
7
var Person = null ;
8
+ var John ;
8
9
9
10
var setup = function ( cache ) {
10
11
return function ( done ) {
@@ -14,7 +15,7 @@ describe("Model.get()", function() {
14
15
cache : cache ,
15
16
methods : {
16
17
UID : function ( ) {
17
- return this . id ;
18
+ return this [ Person . id ] ;
18
19
}
19
20
}
20
21
} ) ;
@@ -26,7 +27,11 @@ describe("Model.get()", function() {
26
27
name : "John Doe"
27
28
} , {
28
29
name : "Jane Doe"
29
- } ] , done ) ;
30
+ } ] , function ( err , people ) {
31
+ John = people [ 0 ] ;
32
+
33
+ return done ( ) ;
34
+ } ) ;
30
35
} ) ;
31
36
} ;
32
37
} ;
@@ -47,39 +52,39 @@ describe("Model.get()", function() {
47
52
before ( setup ( true ) ) ;
48
53
49
54
it ( "should return item with id 1" , function ( done ) {
50
- Person . get ( 1 , function ( err , John ) {
55
+ Person . get ( John [ Person . id ] , function ( err , John ) {
51
56
should . equal ( err , null ) ;
52
57
53
58
John . should . be . a ( "object" ) ;
54
- John . should . have . property ( "id" , 1 ) ;
59
+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
55
60
John . should . have . property ( "name" , "John Doe" ) ;
56
61
57
62
return done ( ) ;
58
63
} ) ;
59
64
} ) ;
60
65
61
66
it ( "should have an UID method" , function ( done ) {
62
- Person . get ( 1 , function ( err , John ) {
67
+ Person . get ( John [ Person . id ] , function ( err , John ) {
63
68
should . equal ( err , null ) ;
64
69
65
70
John . UID . should . be . a ( "function" ) ;
66
- John . UID ( ) . should . equal ( John . id ) ;
71
+ John . UID ( ) . should . equal ( John [ Person . id ] ) ;
67
72
68
73
return done ( ) ;
69
74
} ) ;
70
75
} ) ;
71
76
72
77
describe ( "changing name and getting id 1 again" , function ( ) {
73
78
it ( "should return the original object with unchanged name" , function ( done ) {
74
- Person . get ( 1 , function ( err , John1 ) {
79
+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
75
80
should . equal ( err , null ) ;
76
81
77
82
John1 . name = "James" ;
78
83
79
- Person . get ( 1 , function ( err , John2 ) {
84
+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
80
85
should . equal ( err , null ) ;
81
86
82
- John1 . id . should . equal ( John2 . id ) ;
87
+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
83
88
John2 . name . should . equal ( "John Doe" ) ;
84
89
85
90
return done ( ) ;
@@ -93,15 +98,15 @@ describe("Model.get()", function() {
93
98
Person . settings . set ( "instance.cacheSaveCheck" , false ) ;
94
99
95
100
it ( "should return the same object with the changed name" , function ( done ) {
96
- Person . get ( 1 , function ( err , John1 ) {
101
+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
97
102
should . equal ( err , null ) ;
98
103
99
104
John1 . name = "James" ;
100
105
101
- Person . get ( 1 , function ( err , John2 ) {
106
+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
102
107
should . equal ( err , null ) ;
103
108
104
- John1 . id . should . equal ( John2 . id ) ;
109
+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
105
110
John2 . name . should . equal ( "James" ) ;
106
111
107
112
return done ( ) ;
@@ -117,12 +122,12 @@ describe("Model.get()", function() {
117
122
118
123
describe ( "fetching several times" , function ( ) {
119
124
it ( "should return different objects" , function ( done ) {
120
- Person . get ( 1 , function ( err , John1 ) {
125
+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
121
126
should . equal ( err , null ) ;
122
- Person . get ( 1 , function ( err , John2 ) {
127
+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
123
128
should . equal ( err , null ) ;
124
129
125
- John1 . id . should . equal ( John2 . id ) ;
130
+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
126
131
John1 . should . not . equal ( John2 ) ;
127
132
128
133
return done ( ) ;
@@ -137,14 +142,14 @@ describe("Model.get()", function() {
137
142
138
143
describe ( "fetching again after 0.2 secs" , function ( ) {
139
144
it ( "should return same objects" , function ( done ) {
140
- Person . get ( 1 , function ( err , John1 ) {
145
+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
141
146
should . equal ( err , null ) ;
142
147
143
148
setTimeout ( function ( ) {
144
- Person . get ( 1 , function ( err , John2 ) {
149
+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
145
150
should . equal ( err , null ) ;
146
151
147
- John1 . id . should . equal ( John2 . id ) ;
152
+ John1 [ Person . id ] . should . equal ( John2 [ Person . id ] ) ;
148
153
John1 . should . equal ( John2 ) ;
149
154
150
155
return done ( ) ;
@@ -156,11 +161,11 @@ describe("Model.get()", function() {
156
161
157
162
describe ( "fetching again after 0.7 secs" , function ( ) {
158
163
it ( "should return different objects" , function ( done ) {
159
- Person . get ( 1 , function ( err , John1 ) {
164
+ Person . get ( John [ Person . id ] , function ( err , John1 ) {
160
165
should . equal ( err , null ) ;
161
166
162
167
setTimeout ( function ( ) {
163
- Person . get ( 1 , function ( err , John2 ) {
168
+ Person . get ( John [ Person . id ] , function ( err , John2 ) {
164
169
should . equal ( err , null ) ;
165
170
166
171
John1 . should . not . equal ( John2 ) ;
@@ -177,11 +182,11 @@ describe("Model.get()", function() {
177
182
before ( setup ( ) ) ;
178
183
179
184
it ( "should return item with id 1 like previously" , function ( done ) {
180
- Person . get ( 1 , { } , function ( err , John ) {
185
+ Person . get ( John [ Person . id ] , { } , function ( err , John ) {
181
186
should . equal ( err , null ) ;
182
187
183
188
John . should . be . a ( "object" ) ;
184
- John . should . have . property ( "id" , 1 ) ;
189
+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
185
190
John . should . have . property ( "name" , "John Doe" ) ;
186
191
187
192
return done ( ) ;
@@ -194,7 +199,7 @@ describe("Model.get()", function() {
194
199
195
200
it ( "should throw" , function ( done ) {
196
201
( function ( ) {
197
- Person . get ( 1 ) ;
202
+ Person . get ( John [ Person . id ] ) ;
198
203
} ) . should . throw ( ) ;
199
204
200
205
return done ( ) ;
@@ -218,11 +223,11 @@ describe("Model.get()", function() {
218
223
before ( setup ( true ) ) ;
219
224
220
225
it ( "should accept and try to fetch" , function ( done ) {
221
- Person . get ( [ 1 ] , function ( err , John ) {
226
+ Person . get ( [ John [ Person . id ] ] , function ( err , John ) {
222
227
should . equal ( err , null ) ;
223
228
224
229
John . should . be . a ( "object" ) ;
225
- John . should . have . property ( "id" , 1 ) ;
230
+ John . should . have . property ( Person . id , John [ Person . id ] ) ;
226
231
John . should . have . property ( "name" , "John Doe" ) ;
227
232
228
233
return done ( ) ;
@@ -269,7 +274,6 @@ describe("Model.get()", function() {
269
274
OtherPerson . get ( "Jane Doe" , function ( err , person ) {
270
275
should . equal ( err , null ) ;
271
276
272
- person . id . should . be . a ( "number" ) ;
273
277
person . name . should . equal ( "Jane Doe" ) ;
274
278
275
279
return done ( ) ;
0 commit comments