@@ -198,6 +198,9 @@ describe('Model', function() {
198
198
data : [ {
199
199
id : '1' ,
200
200
type : 'books'
201
+ } , {
202
+ id : '2' ,
203
+ type : 'books'
201
204
} ]
202
205
} ,
203
206
bio : {
@@ -217,6 +220,29 @@ describe('Model', function() {
217
220
id : '1' ,
218
221
attributes : {
219
222
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
+ }
220
246
}
221
247
} ,
222
248
{
@@ -300,7 +326,7 @@ describe('Model', function() {
300
326
301
327
it ( 'assigns hasMany relationships correctly' , function ( ) {
302
328
let instance = Model . fromJsonapi ( doc . data , doc ) ;
303
- expect ( instance . books . length ) . to . eq ( 1 ) ;
329
+ expect ( instance . books . length ) . to . eq ( 2 ) ;
304
330
let book = instance . books [ 0 ] ;
305
331
expect ( book ) . to . be . instanceof ( Book ) ;
306
332
expect ( book . title ) . to . eq ( "Where's My Butt?" ) ;
@@ -330,6 +356,15 @@ describe('Model', function() {
330
356
expect ( authors [ 1 ] . firstName ) . to . eq ( 'Maurice Sendak' ) ;
331
357
} ) ;
332
358
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
+
333
368
it ( 'skips relationships without data' , function ( ) {
334
369
let instance = Model . fromJsonapi ( doc . data , doc ) ;
335
370
expect ( instance . tags ) . to . eql ( [ ] ) ;
0 commit comments