@@ -25,16 +25,20 @@ describe('Model finders', function() {
25
25
} ) ;
26
26
} ) ;
27
27
28
- //it('returns a promise that resolves the correct instance', function() {
29
- //return expect(resultData(Person.find(1))).to.eventually
30
- //.be.instanceof(Person).and
31
- //.have.property('id', '1');
32
- //});
28
+ it ( 'returns a promise that resolves the correct instance' , function ( done ) {
29
+ resultData ( Person . find ( 1 ) ) . then ( ( data ) => {
30
+ expect ( data ) . to . be . instanceof ( Person ) . and
31
+ . have . property ( 'id' , '1' ) ;
32
+ done ( ) ;
33
+ } ) ;
34
+ } ) ;
33
35
34
- //it('assigns attributes correctly', function() {
35
- //return expect(resultData(Person.find(1))).to.eventually
36
- //.have.property('name', 'John')
37
- //});
36
+ it ( 'assigns attributes correctly' , function ( done ) {
37
+ resultData ( Person . find ( 1 ) ) . then ( ( data ) => {
38
+ expect ( data ) . to . have . property ( 'name' , 'John' ) ;
39
+ done ( ) ;
40
+ } ) ;
41
+ } ) ;
38
42
39
43
describe ( 'when API response returns a different type than the caller' , function ( ) {
40
44
before ( function ( ) {
@@ -70,7 +74,7 @@ describe('Model finders', function() {
70
74
it ( 'returns a promise that resolves the correct instances' , function ( ) {
71
75
return expect ( resultData ( Person . first ( ) ) ) . to . eventually
72
76
. be . instanceof ( Person )
73
- . have . property ( 'id' , '1' )
77
+ . have . property ( 'id' , '1' ) ;
74
78
} ) ;
75
79
} ) ;
76
80
@@ -84,11 +88,14 @@ describe('Model finders', function() {
84
88
} ) ;
85
89
} ) ;
86
90
87
- //it('returns a promise that resolves the correct instances', function() {
88
- //return expect(resultData(Person.all())).to.eventually
89
- //.all.be.instanceof(Person)
90
- //.all.have.property('id', '1')
91
- //});
91
+ it ( 'returns a promise that resolves the correct instances' , function ( done ) {
92
+ resultData ( Person . all ( ) ) . then ( ( data ) => {
93
+ expect ( data . length ) . to . eq ( 1 ) ;
94
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
95
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '1' ) ;
96
+ done ( ) ;
97
+ } ) ;
98
+ } ) ;
92
99
93
100
describe ( 'response includes a meta payload' , function ( ) {
94
101
beforeEach ( function ( ) {
@@ -123,11 +130,14 @@ describe('Model finders', function() {
123
130
} ) ;
124
131
} ) ;
125
132
126
- //it('queries correctly', function() {
127
- //return expect(resultData(Person.page(2).all())).to.eventually
128
- //.all.be.instanceof(Person)
129
- //.all.have.property('id', '2')
130
- //});
133
+ it ( 'queries correctly' , function ( done ) {
134
+ resultData ( Person . page ( 2 ) . all ( ) ) . then ( ( data ) => {
135
+ expect ( data . length ) . to . eq ( 1 )
136
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
137
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
138
+ done ( ) ;
139
+ } ) ;
140
+ } ) ;
131
141
132
142
describe ( 'when merging association #page' , function ( ) {
133
143
before ( function ( ) {
@@ -139,12 +149,15 @@ describe('Model finders', function() {
139
149
} ) ;
140
150
} ) ;
141
151
142
- //it('queries correctly', function() {
143
- //let bookScope = Book.page(10);
144
- //let personScope = Person.page(5).merge({ books: bookScope });
145
- //return expect(resultData(personScope.all())).to.eventually
146
- //.all.be.instanceof(Person)
147
- //});
152
+ it ( 'queries correctly' , function ( done ) {
153
+ let bookScope = Book . page ( 10 ) ;
154
+ let personScope = Person . page ( 5 ) . merge ( { books : bookScope } ) ;
155
+ resultData ( personScope . all ( ) ) . then ( ( data ) => {
156
+ expect ( data . length ) . to . eq ( 1 ) ;
157
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
158
+ done ( ) ;
159
+ } ) ;
160
+ } ) ;
148
161
} ) ;
149
162
} ) ;
150
163
@@ -157,10 +170,13 @@ describe('Model finders', function() {
157
170
} ) ;
158
171
} ) ;
159
172
160
- //it('queries correctly', function() {
161
- //return expect(resultData(Author.per(5).all())).to.eventually
162
- //.all.be.instanceof(Person)
163
- //});
173
+ it ( 'queries correctly' , function ( done ) {
174
+ resultData ( Author . per ( 5 ) . all ( ) ) . then ( ( data ) => {
175
+ expect ( data . length ) . to . eq ( 1 ) ;
176
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
177
+ done ( ) ;
178
+ } ) ;
179
+ } ) ;
164
180
165
181
describe ( 'when merging association #per' , function ( ) {
166
182
before ( function ( ) {
@@ -172,12 +188,15 @@ describe('Model finders', function() {
172
188
} ) ;
173
189
} ) ;
174
190
175
- //it('queries correctly', function() {
176
- //let bookScope = Book.per(2);
177
- //let personScope = Person.per(5).merge({ books: bookScope });
178
- //return expect(resultData(personScope.all())).to.eventually
179
- //.all.be.instanceof(Person)
180
- //});
191
+ it ( 'queries correctly' , function ( done ) {
192
+ let bookScope = Book . per ( 2 ) ;
193
+ let personScope = Person . per ( 5 ) . merge ( { books : bookScope } ) ;
194
+ resultData ( personScope . all ( ) ) . then ( ( data ) => {
195
+ expect ( data . length ) . to . eq ( 1 ) ;
196
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
197
+ done ( ) ;
198
+ } ) ;
199
+ } ) ;
181
200
} ) ;
182
201
} ) ;
183
202
@@ -190,11 +209,14 @@ describe('Model finders', function() {
190
209
} ) ;
191
210
} ) ;
192
211
193
- //it('queries correctly', function() {
194
- //return expect(resultData(Person.order('foo').order({ bar: 'desc' }).all())).to.eventually
195
- //.all.be.instanceof(Person)
196
- //.all.have.property('id', '2')
197
- //});
212
+ it ( 'queries correctly' , function ( done ) {
213
+ resultData ( Person . order ( 'foo' ) . order ( { bar : 'desc' } ) . all ( ) ) . then ( ( data ) => {
214
+ expect ( data . length ) . to . eq ( 1 ) ;
215
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
216
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
217
+ done ( ) ;
218
+ } ) ;
219
+ } ) ;
198
220
199
221
describe ( 'when merging association #order' , function ( ) {
200
222
before ( function ( ) {
@@ -206,14 +228,17 @@ describe('Model finders', function() {
206
228
} ) ;
207
229
} ) ;
208
230
209
- //it('queries correctly', function() {
210
- //let bookScope = Book.order('title').order({ pages: 'desc' });
211
- //let scope = Person.order('foo');
212
- //scope = scope.merge({ books: bookScope })
213
- //return expect(resultData(scope.all())).to.eventually
214
- //.all.be.instanceof(Person)
215
- //.all.have.property('id', '2')
216
- //});
231
+ it ( 'queries correctly' , function ( done ) {
232
+ let bookScope = Book . order ( 'title' ) . order ( { pages : 'desc' } ) ;
233
+ let scope = Person . order ( 'foo' ) ;
234
+ scope = scope . merge ( { books : bookScope } )
235
+ resultData ( scope . all ( ) ) . then ( ( data ) => {
236
+ expect ( data . length ) . to . eq ( 1 ) ;
237
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
238
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
239
+ done ( ) ;
240
+ } ) ;
241
+ } ) ;
217
242
} ) ;
218
243
} ) ;
219
244
@@ -226,11 +251,14 @@ describe('Model finders', function() {
226
251
} ) ;
227
252
} ) ;
228
253
229
- //it('queries correctly', function() {
230
- //return expect(resultData(Person.where({ id: 2 }).where({ a: 'b' }).all())).to.eventually
231
- //.all.be.instanceof(Person)
232
- //.all.have.property('id', '2')
233
- //});
254
+ it ( 'queries correctly' , function ( done ) {
255
+ resultData ( Person . where ( { id : 2 } ) . where ( { a : 'b' } ) . all ( ) ) . then ( ( data ) => {
256
+ expect ( data . length ) . to . eq ( 1 ) ;
257
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
258
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
259
+ done ( ) ;
260
+ } ) ;
261
+ } ) ;
234
262
235
263
describe ( 'when merging association #where' , function ( ) {
236
264
before ( function ( ) {
@@ -242,12 +270,16 @@ describe('Model finders', function() {
242
270
} ) ;
243
271
} ) ;
244
272
245
- //it('queries correctly', function() {
246
- //let bookScope = Book.where({ title: 'It' });
247
- //let personScope = Person.where({id : 1 }).merge({ books: bookScope });
248
- //return expect(resultData(personScope.all())).to.eventually
249
- //.all.be.instanceof(Person)
250
- //});
273
+ it ( 'queries correctly' , function ( done ) {
274
+ let bookScope = Book . where ( { title : 'It' } ) ;
275
+ let personScope = Person . where ( { id : 1 } ) . merge ( { books : bookScope } ) ;
276
+
277
+ resultData ( personScope . all ( ) ) . then ( ( data ) => {
278
+ expect ( data . length ) . to . eq ( 1 ) ;
279
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
280
+ done ( ) ;
281
+ } ) ;
282
+ } ) ;
251
283
} ) ;
252
284
} ) ;
253
285
@@ -260,11 +292,15 @@ describe('Model finders', function() {
260
292
} ) ;
261
293
} ) ;
262
294
263
- //it('queries correctly', function() {
264
- //let scope = Person.stats({ total: ['count', 'sum'] });
265
- //return expect(resultData(scope.all())).to.eventually
266
- //.all.be.instanceof(Person)
267
- //});
295
+ it ( 'queries correctly' , function ( done ) {
296
+ let scope = Person . stats ( { total : [ 'count' , 'sum' ] } ) ;
297
+
298
+ resultData ( scope . all ( ) ) . then ( ( data ) => {
299
+ expect ( data . length ) . to . eq ( 1 ) ;
300
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
301
+ done ( ) ;
302
+ } ) ;
303
+ } ) ;
268
304
269
305
describe ( 'when merging association #stats' , function ( ) {
270
306
before ( function ( ) {
@@ -276,14 +312,17 @@ describe('Model finders', function() {
276
312
} ) ;
277
313
} ) ;
278
314
279
- // it('queries correctly', function() {
280
- // let bookScope = Book.stats({ pages: ['average'] });
281
- // let scope = Person.stats({ total: ['count', 'sum'] });
282
- // scope = scope.merge({ books: bookScope });
315
+ it ( 'queries correctly' , function ( done ) {
316
+ let bookScope = Book . stats ( { pages : [ 'average' ] } ) ;
317
+ let scope = Person . stats ( { total : [ 'count' , 'sum' ] } ) ;
318
+ scope = scope . merge ( { books : bookScope } ) ;
283
319
284
- //return expect(resultData(scope.all())).to.eventually
285
- //.all.be.instanceof(Person)
286
- //});
320
+ resultData ( scope . all ( ) ) . then ( ( data ) => {
321
+ expect ( data . length ) . to . eq ( 1 ) ;
322
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
323
+ done ( ) ;
324
+ } ) ;
325
+ } ) ;
287
326
} ) ;
288
327
} ) ;
289
328
@@ -296,11 +335,14 @@ describe('Model finders', function() {
296
335
} ) ;
297
336
} ) ;
298
337
299
- //it('queries correctly', function() {
300
- //return expect(resultData(Person.select({ people: ['name', 'age'] }).all())).to.eventually
301
- //.all.be.instanceof(Person)
302
- //.all.have.property('id', '2')
303
- //});
338
+ it ( 'queries correctly' , function ( done ) {
339
+ resultData ( Person . select ( { people : [ 'name' , 'age' ] } ) . all ( ) ) . then ( ( data ) => {
340
+ expect ( data . length ) . to . eq ( 1 ) ;
341
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
342
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
343
+ done ( ) ;
344
+ } ) ;
345
+ } ) ;
304
346
} ) ;
305
347
306
348
describe ( '#select_extra' , function ( ) {
@@ -312,11 +354,14 @@ describe('Model finders', function() {
312
354
} ) ;
313
355
} ) ;
314
356
315
- //it('queries correctly', function() {
316
- //return expect(resultData(Person.selectExtra({ people: ['net_worth', 'best_friend'] }).all())).to.eventually
317
- //.all.be.instanceof(Person)
318
- //.all.have.property('id', '2')
319
- //});
357
+ it ( 'queries correctly' , function ( done ) {
358
+ resultData ( Person . selectExtra ( { people : [ 'net_worth' , 'best_friend' ] } ) . all ( ) ) . then ( ( data ) => {
359
+ expect ( data . length ) . to . eq ( 1 ) ;
360
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
361
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
362
+ done ( ) ;
363
+ } ) ;
364
+ } ) ;
320
365
} ) ;
321
366
322
367
describe ( '#includes' , function ( ) {
@@ -331,10 +376,12 @@ describe('Model finders', function() {
331
376
} ) ;
332
377
} ) ;
333
378
334
- //it('queries correctly', function() {
335
- //return expect(resultData(Person.includes({ a: ['b', { c: 'd' }] }).all())).to.eventually
336
- //.all.be.instanceof(Person)
337
- //.all.have.property('id', '2')
338
- //});
379
+ it ( 'queries correctly' , function ( ) {
380
+ resultData ( Person . includes ( { a : [ 'b' , { c : 'd' } ] } ) . all ( ) ) . then ( ( data ) => {
381
+ expect ( data . length ) . to . eq ( 1 ) ;
382
+ expect ( data [ 0 ] ) . to . be . instanceof ( Person ) ;
383
+ expect ( data [ 0 ] ) . to . have . property ( 'id' , '2' ) ;
384
+ } ) ;
385
+ } ) ;
339
386
} ) ;
340
387
} ) ;
0 commit comments