@@ -432,6 +432,41 @@ describe('Model', function() {
432432 } ) ;
433433 } ) ;
434434
435+ describe ( 'when a has-many is marked for disassociation' , function ( ) {
436+ let newDoc , instance , book ;
437+
438+ beforeEach ( function ( ) {
439+ book = new Book ( { id : '1' } ) ;
440+ book . isPersisted ( true ) ;
441+ book . isMarkedForDisassociation ( true ) ;
442+
443+ instance = new Author ( { books : [ book ] } ) ;
444+
445+ newDoc = {
446+ data : {
447+ id : '1' ,
448+ type : 'authors'
449+ }
450+ }
451+ } ) ;
452+
453+ describe ( 'when the relation is part of the include directive' , function ( ) {
454+ it ( 'is removed from the array' , function ( ) {
455+ expect ( instance . books . length ) . to . eq ( 1 ) ;
456+ instance . fromJsonapi ( newDoc . data , newDoc , { books : { } } ) ;
457+ expect ( instance . books . length ) . to . eq ( 0 ) ;
458+ } ) ;
459+ } ) ;
460+
461+ describe ( 'when the relation is not part of the include directive' , function ( ) {
462+ it ( 'is NOT removed from the array' , function ( ) {
463+ expect ( instance . books . length ) . to . eq ( 1 ) ;
464+ instance . fromJsonapi ( newDoc . data , newDoc , { } ) ;
465+ expect ( instance . books . length ) . to . eq ( 1 ) ;
466+ } ) ;
467+ } ) ;
468+ } ) ;
469+
435470 describe ( 'when a belongs-to is marked for destruction' , function ( ) {
436471 let newDoc , instance , book ;
437472
@@ -484,6 +519,59 @@ describe('Model', function() {
484519 } ) ;
485520 } ) ;
486521 } ) ;
522+
523+ describe ( 'when a belongs-to is marked for disassociation' , function ( ) {
524+ let newDoc , instance , book ;
525+
526+ beforeEach ( function ( ) {
527+ let genre = new Genre ( { id : '1' } ) ;
528+ genre . isPersisted ( true ) ;
529+ genre . isMarkedForDisassociation ( true ) ;
530+
531+ book = new Book ( { id : '1' , genre : genre } ) ;
532+ book . isPersisted ( true ) ;
533+
534+ instance = new Author ( { books : [ book ] } ) ;
535+
536+ newDoc = {
537+ data : {
538+ id : '1' ,
539+ type : 'authors'
540+ } ,
541+ relationships : {
542+ books : {
543+ data : [
544+ { id : '1' , type : 'books' }
545+ ]
546+ }
547+ } ,
548+ included : [
549+ {
550+ id : '1' ,
551+ type : 'books' ,
552+ attributes : { title : 'whatever' }
553+ }
554+ ]
555+ }
556+ } ) ;
557+
558+ it ( 'is set to null' , function ( ) {
559+ expect ( instance . books [ 0 ] . genre ) . to . be . instanceof ( Genre ) ;
560+ instance . fromJsonapi ( newDoc . data , newDoc , { books : { genre : { } } } ) ;
561+ expect ( instance . books [ 0 ] . genre ) . to . eq ( null ) ;
562+ } ) ;
563+
564+ describe ( 'within a nested destruction' , function ( ) {
565+ beforeEach ( function ( ) {
566+ book . isMarkedForDisassociation ( true ) ;
567+ } ) ;
568+
569+ it ( 'is removed via the parent' , function ( ) {
570+ instance . fromJsonapi ( newDoc . data , newDoc , { books : { genre : { } } } ) ;
571+ expect ( instance . books . length ) . to . eq ( 0 ) ;
572+ } ) ;
573+ } ) ;
574+ } ) ;
487575 } ) ;
488576
489577 describe ( 'isMarkedForDestruction' , function ( ) {
@@ -497,6 +585,17 @@ describe('Model', function() {
497585 } ) ;
498586 } ) ;
499587
588+ describe ( 'isMarkedForDisassociation' , function ( ) {
589+ it ( 'toggles correctly' , function ( ) {
590+ instance = new Author ( ) ;
591+ expect ( instance . isMarkedForDisassociation ( ) ) . to . eq ( false )
592+ instance . isMarkedForDisassociation ( true ) ;
593+ expect ( instance . isMarkedForDisassociation ( ) ) . to . eq ( true )
594+ instance . isMarkedForDisassociation ( false ) ;
595+ expect ( instance . isMarkedForDisassociation ( ) ) . to . eq ( false )
596+ } ) ;
597+ } ) ;
598+
500599 describe ( 'isDirty' , function ( ) {
501600 describe ( 'when an attribute changes' , function ( ) {
502601 it ( 'is marked as dirty' , function ( ) {
@@ -546,8 +645,12 @@ describe('Model', function() {
546645 } ) ;
547646
548647 describe ( 'when marked for disassociation' , function ( ) {
549- // disassociations not implemented yet
550- xit ( 'is dirty' , function ( ) {
648+ it ( 'is dirty' , function ( ) {
649+ instance = new Author ( ) ;
650+ instance . isPersisted ( true ) ;
651+ expect ( instance . isDirty ( ) ) . to . eq ( false ) ;
652+ instance . isMarkedForDisassociation ( true ) ;
653+ expect ( instance . isDirty ( ) ) . to . eq ( true ) ;
551654 } ) ;
552655 } ) ;
553656
@@ -659,6 +762,20 @@ describe('Model', function() {
659762 expect ( instance . isDirty ( ) ) . to . eq ( false ) ;
660763 } ) ;
661764 } ) ;
765+
766+ describe ( 'when a hasMany relationship has a member marked for disassociation' , function ( ) {
767+ it ( 'is dirty' , function ( ) {
768+ let book = new Book ( { id : 1 } ) ;
769+ book . isPersisted ( true ) ;
770+ instance . books = [ book ] ;
771+ instance . isPersisted ( true ) ;
772+
773+ expect ( instance . isDirty ( 'books' ) ) . to . eq ( false ) ;
774+ book . isMarkedForDisassociation ( true ) ;
775+ expect ( instance . isDirty ( 'books' ) ) . to . eq ( true ) ;
776+ expect ( instance . isDirty ( ) ) . to . eq ( false ) ;
777+ } ) ;
778+ } ) ;
662779 } ) ;
663780 } ) ;
664781} ) ;
0 commit comments