@@ -269,9 +269,10 @@ describe('include', function() {
269269 if ( err ) return done ( err ) ;
270270
271271 var passport = user . passports ( ) [ 0 ] ;
272- passport . id . should . equal ( 1 ) ;
273- passport . ownerId . should . equal ( 1 ) ;
274- passport . number . should . equal ( '1' ) ;
272+ // eql instead of equal because mongo uses object id type
273+ passport . id . should . eql ( createdPassports [ 0 ] . id ) ;
274+ passport . ownerId . should . eql ( createdPassports [ 0 ] . ownerId ) ;
275+ passport . number . should . eql ( createdPassports [ 0 ] . number ) ;
275276
276277 done ( ) ;
277278 } ) ;
@@ -284,8 +285,8 @@ describe('include', function() {
284285 scope : {
285286 where : {
286287 and : [
287- { id : 1 } ,
288- { userId : 1 } ,
288+ { id : createdPosts [ 0 ] . id } ,
289+ { userId : createdPosts [ 0 ] . userId } ,
289290 { title : 'Post A' } ,
290291 ] ,
291292 } ,
@@ -296,13 +297,14 @@ describe('include', function() {
296297
297298 user . name . should . equal ( 'User A' ) ;
298299 user . age . should . equal ( 21 ) ;
299- user . id . should . equal ( 1 ) ;
300+ user . id . should . eql ( createdUsers [ 0 ] . id ) ;
300301 var posts = user . posts ( ) ;
301302 posts . length . should . equal ( 1 ) ;
302303 var post = posts [ 0 ] ;
303304 post . title . should . equal ( 'Post A' ) ;
304- post . userId . should . equal ( 1 ) ;
305- post . id . should . equal ( 1 ) ;
305+ // eql instead of equal because mongo uses object id type
306+ post . userId . should . eql ( createdPosts [ 0 ] . userId ) ;
307+ post . id . should . eql ( createdPosts [ 0 ] . id ) ;
306308
307309 done ( ) ;
308310 } ) ;
@@ -337,7 +339,7 @@ describe('include', function() {
337339 if ( err ) return done ( err ) ;
338340
339341 var ids = user . posts ( ) . map ( function ( p ) { return p . id ; } ) ;
340- ids . should . eql ( [ 2 , 3 ] ) ;
342+ ids . should . eql ( [ createdPosts [ 1 ] . id , createdPosts [ 2 ] . id ] ) ;
341343
342344 done ( ) ;
343345 } ) ;
@@ -355,7 +357,7 @@ describe('include', function() {
355357 if ( err ) return done ( err ) ;
356358
357359 var ids = user . posts ( ) . map ( function ( p ) { return p . id ; } ) ;
358- ids . should . eql ( [ 2 , 3 ] ) ;
360+ ids . should . eql ( [ createdPosts [ 1 ] . id , createdPosts [ 2 ] . id ] ) ;
359361
360362 done ( ) ;
361363 } ) ;
@@ -368,7 +370,11 @@ describe('include', function() {
368370
369371 var posts = user . posts ( ) ;
370372 var ids = posts . map ( function ( p ) { return p . id ; } ) ;
371- ids . should . eql ( [ 1 , 2 , 3 ] ) ;
373+ ids . should . eql ( [
374+ createdPosts [ 0 ] . id ,
375+ createdPosts [ 1 ] . id ,
376+ createdPosts [ 2 ] . id ,
377+ ] ) ;
372378
373379 done ( ) ;
374380 } ) ;
@@ -428,11 +434,13 @@ describe('include', function() {
428434
429435 user . name . should . equal ( 'User A' ) ;
430436 user . age . should . equal ( 21 ) ;
431- user . id . should . equal ( 1 ) ;
437+ // eql instead of equal because mongo uses object id type
438+ user . id . should . eql ( createdUsers [ 0 ] . id ) ;
432439 var profile = user . profile ( ) ;
433440 profile . profileName . should . equal ( 'Profile A' ) ;
434- profile . userId . should . equal ( 1 ) ;
435- profile . id . should . equal ( 1 ) ;
441+ // eql instead of equal because mongo uses object id type
442+ profile . userId . should . eql ( createdProfiles [ 0 ] . userId ) ;
443+ profile . id . should . eql ( createdProfiles [ 0 ] . id ) ;
436444
437445 done ( ) ;
438446 } ) ;
@@ -444,7 +452,8 @@ describe('include', function() {
444452
445453 user . name . should . equal ( 'User A' ) ;
446454 user . age . should . equal ( 21 ) ;
447- user . id . should . equal ( 1 ) ;
455+ // eql instead of equal because mongo uses object id type
456+ user . id . should . eql ( createdUsers [ 0 ] . id ) ;
448457 user . posts ( ) . length . should . equal ( 3 ) ;
449458
450459 done ( ) ;
@@ -478,18 +487,18 @@ describe('include', function() {
478487 patient . address ( address ) ;
479488 patient . save ( function ( ) {
480489 physician . patients ( { include : 'address' } ,
481- function ( err , posts ) {
482- if ( err ) return done ( err ) ;
483-
484- posts . should . be . an . instanceOf ( Array ) . and . have . length ( 1 ) ;
485- var p = posts [ 0 ] ;
486- p . name . should . equal ( 'a' ) ;
487- p . addressId . should . equal ( 1 ) ;
488- p . address ( ) . id . should . equal ( 1 ) ;
489- p . address ( ) . name . should . equal ( 'z' ) ;
490-
491- done ( ) ;
492- } ) ;
490+ function ( err , patients ) {
491+ if ( err ) return done ( err ) ;
492+
493+ patients . should . have . length ( 1 ) ;
494+ var p = patients [ 0 ] ;
495+ p . name . should . equal ( 'a' ) ;
496+ p . addressId . should . eql ( patient . addressId ) ;
497+ p . address ( ) . id . should . eql ( address . id ) ;
498+ p . address ( ) . name . should . equal ( 'z' ) ;
499+
500+ done ( ) ;
501+ } ) ;
493502 } ) ;
494503 } ) ;
495504 } ) ;
@@ -502,12 +511,12 @@ describe('include', function() {
502511 if ( err ) return done ( err ) ;
503512
504513 profile . profileName . should . equal ( 'Profile A' ) ;
505- profile . userId . should . equal ( 1 ) ;
506- profile . id . should . equal ( 1 ) ;
514+ profile . userId . should . eql ( createdProfiles [ 0 ] . userId ) ;
515+ profile . id . should . eql ( createdProfiles [ 0 ] . id ) ;
507516 var user = profile . user ( ) ;
508517 user . name . should . equal ( 'User A' ) ;
509518 user . age . should . equal ( 21 ) ;
510- user . id . should . equal ( 1 ) ;
519+ user . id . should . eql ( createdUsers [ 0 ] . id ) ;
511520
512521 done ( ) ;
513522 } ) ;
@@ -946,6 +955,10 @@ describe('include', function() {
946955 } ) ;
947956} ) ;
948957
958+ var createdUsers = [ ] ;
959+ var createdPassports = [ ] ;
960+ var createdProfiles = [ ] ;
961+ var createdPosts = [ ] ;
949962function setup ( done ) {
950963 db = getSchema ( ) ;
951964 City = db . define ( 'City' ) ;
@@ -991,10 +1004,6 @@ function setup(done) {
9911004 Part . hasAndBelongsToMany ( Assembly ) ;
9921005
9931006 db . automigrate ( function ( ) {
994- var createdUsers = [ ] ;
995- var createdPassports = [ ] ;
996- var createdProfiles = [ ] ;
997- var createdPosts = [ ] ;
9981007 createUsers ( ) ;
9991008 function createUsers ( ) {
10001009 clearAndCreate (
0 commit comments