@@ -198,6 +198,9 @@ describe('Model', function() {
198198 data : [ {
199199 id : '1' ,
200200 type : 'books'
201+ } , {
202+ id : '2' ,
203+ type : 'books'
201204 } ]
202205 } ,
203206 bio : {
@@ -217,6 +220,29 @@ describe('Model', function() {
217220 id : '1' ,
218221 attributes : {
219222 title : "Where's My Butt?"
223+ } ,
224+ relationships : {
225+ author : {
226+ data : {
227+ id : '2' ,
228+ type : 'authors'
229+ } ,
230+ }
231+ }
232+ } ,
233+ {
234+ type : 'books' ,
235+ id : '2' ,
236+ attributes : {
237+ title : "Catcher in the Rye"
238+ } ,
239+ relationships : {
240+ author : {
241+ data : {
242+ id : '2' ,
243+ type : 'authors'
244+ } ,
245+ }
220246 }
221247 } ,
222248 {
@@ -300,7 +326,7 @@ describe('Model', function() {
300326
301327 it ( 'assigns hasMany relationships correctly' , function ( ) {
302328 let instance = Model . fromJsonapi ( doc . data , doc ) ;
303- expect ( instance . books . length ) . to . eq ( 1 ) ;
329+ expect ( instance . books . length ) . to . eq ( 2 ) ;
304330 let book = instance . books [ 0 ] ;
305331 expect ( book ) . to . be . instanceof ( Book ) ;
306332 expect ( book . title ) . to . eq ( "Where's My Butt?" ) ;
@@ -330,6 +356,15 @@ describe('Model', function() {
330356 expect ( authors [ 1 ] . firstName ) . to . eq ( 'Maurice Sendak' ) ;
331357 } ) ;
332358
359+ it ( 'assigns duplicated nested relationships correctly' , function ( ) {
360+ let instance = Model . fromJsonapi ( doc . data , doc ) ;
361+ let book1 = instance . books [ 0 ] ;
362+ let book2 = instance . books [ 1 ] ;
363+
364+ expect ( book1 . author . firstName ) . to . eq ( "Maurice Sendak" ) ;
365+ expect ( book2 . author . firstName ) . to . eq ( "Maurice Sendak" ) ;
366+ } ) ;
367+
333368 it ( 'skips relationships without data' , function ( ) {
334369 let instance = Model . fromJsonapi ( doc . data , doc ) ;
335370 expect ( instance . tags ) . to . eql ( [ ] ) ;
0 commit comments