@@ -367,59 +367,28 @@ describe("hasMany", function () {
367367 } ) ;
368368 } ) ;
369369 } ) ;
370- } ) ;
371-
372- describe ( "addAccessor" , function ( ) {
373- before ( setup ( ) ) ;
374370
375371 it ( "should accept array as list of associations" , function ( done ) {
376372 Pet . find ( function ( err , pets ) {
377- Person . find ( { name : "Justin" } ) . first ( function ( err , Justin ) {
378- should . equal ( err , null ) ;
379-
380- Justin . addPets ( pets , function ( err ) {
381- should . equal ( err , null ) ;
382-
383- Justin . getPets ( function ( err , all_pets ) {
384- should . equal ( err , null ) ;
385-
386- should ( Array . isArray ( all_pets ) ) ;
387- all_pets . length . should . equal ( pets . length ) ;
388-
389- return done ( ) ;
390- } ) ;
391- } ) ;
392- } ) ;
393- } ) ;
394- } ) ;
395- } ) ;
373+ var petCount = pets . length ;
396374
397- describe ( "setAccessor" , function ( ) {
398- before ( setup ( ) ) ;
399-
400- it ( "clears current associations" , function ( done ) {
401- Pet . find ( { name : "Deco" } , function ( err , pets ) {
402- var Deco = pets [ 0 ] ;
403-
404- Person . find ( { name : "Jane" } ) . first ( function ( err , Jane ) {
375+ Person . find ( { name : "Justin" } ) . first ( function ( err , Justin ) {
405376 should . equal ( err , null ) ;
406377
407- Jane . getPets ( function ( err , pets ) {
378+ Justin . getPets ( function ( err , justinsPets ) {
408379 should . equal ( err , null ) ;
409380
410- should ( Array . isArray ( pets ) ) ;
411- pets . length . should . equal ( 1 ) ;
412- pets [ 0 ] . name . should . equal ( "Mutt" ) ;
381+ should . equal ( justinsPets . length , 2 ) ;
413382
414- Jane . setPets ( Deco , function ( err ) {
383+ Justin . addPets ( pets , function ( err ) {
415384 should . equal ( err , null ) ;
416385
417- Jane . getPets ( function ( err , pets ) {
386+ Justin . getPets ( function ( err , justinsPets ) {
418387 should . equal ( err , null ) ;
419388
420- should ( Array . isArray ( pets ) ) ;
421- pets . length . should . equal ( 1 ) ;
422- pets [ 0 ] . name . should . equal ( Deco . name ) ;
389+ should ( Array . isArray ( justinsPets ) ) ;
390+ // We're not checking uniqueness.
391+ should . equal ( justinsPets . length , petCount + 2 ) ;
423392
424393 return done ( ) ;
425394 } ) ;
@@ -428,6 +397,18 @@ describe("hasMany", function () {
428397 } ) ;
429398 } ) ;
430399 } ) ;
400+
401+ it ( "should throw if no items passed" , function ( done ) {
402+ Person . one ( function ( err , person ) {
403+ should . equal ( err , null ) ;
404+
405+ ( function ( ) {
406+ person . addPets ( function ( ) { } ) ;
407+ } ) . should . throw ( ) ;
408+
409+ return done ( ) ;
410+ } ) ;
411+ } ) ;
431412 } ) ;
432413
433414 describe ( "setAccessor" , function ( ) {
@@ -475,15 +456,47 @@ describe("hasMany", function () {
475456 } ) ;
476457 } ) ;
477458
478- it ( "should throw if no items passed" , function ( done ) {
479- Person . one ( function ( err , person ) {
459+ it ( "should remove all associations if an empty array is passed" , function ( done ) {
460+ Person . find ( { name : "Justin" } ) . first ( function ( err , Justin ) {
480461 should . equal ( err , null ) ;
481462
482- ( function ( ) {
483- person . addPets ( function ( ) { } ) ;
484- } ) . should . throw ( ) ;
463+ Justin . setPets ( [ ] , function ( err ) {
464+ should . equal ( err , null ) ;
485465
486- return done ( ) ;
466+ return done ( ) ;
467+ } ) ;
468+ } ) ;
469+ } ) ;
470+
471+ it ( "clears current associations" , function ( done ) {
472+ Pet . find ( { name : "Deco" } , function ( err , pets ) {
473+ var Deco = pets [ 0 ] ;
474+
475+ Person . find ( { name : "Jane" } ) . first ( function ( err , Jane ) {
476+ should . equal ( err , null ) ;
477+
478+ Jane . getPets ( function ( err , pets ) {
479+ should . equal ( err , null ) ;
480+
481+ should ( Array . isArray ( pets ) ) ;
482+ pets . length . should . equal ( 1 ) ;
483+ pets [ 0 ] . name . should . equal ( "Mutt" ) ;
484+
485+ Jane . setPets ( Deco , function ( err ) {
486+ should . equal ( err , null ) ;
487+
488+ Jane . getPets ( function ( err , pets ) {
489+ should . equal ( err , null ) ;
490+
491+ should ( Array . isArray ( pets ) ) ;
492+ pets . length . should . equal ( 1 ) ;
493+ pets [ 0 ] . name . should . equal ( Deco . name ) ;
494+
495+ return done ( ) ;
496+ } ) ;
497+ } ) ;
498+ } ) ;
499+ } ) ;
487500 } ) ;
488501 } ) ;
489502 } ) ;
0 commit comments