@@ -23,7 +23,8 @@ module("integration/serializer/rest - RESTSerializer", {
23
23
} ) ;
24
24
EvilMinion = DS . Model . extend ( {
25
25
superVillain : DS . belongsTo ( 'super-villain' , { async : false } ) ,
26
- name : DS . attr ( 'string' )
26
+ name : DS . attr ( 'string' ) ,
27
+ doomsdayDevice : DS . belongsTo ( 'doomsday-device' , { async : false } )
27
28
} ) ;
28
29
YellowMinion = EvilMinion . extend ( {
29
30
eyes : DS . attr ( 'number' )
@@ -894,3 +895,69 @@ test('Serializer should respect the attrs hash in links', function(assert) {
894
895
895
896
assert . equal ( documentHash . data . relationships . evilMinions . links . related , 'me/minions' ) ;
896
897
} ) ;
898
+
899
+ // https://github.com/emberjs/data/issues/3805
900
+ test ( 'normalizes sideloaded single record so that it sideloads correctly - belongsTo - GH-3805' , function ( assert ) {
901
+ env . registry . register ( "serializer:doomsday-device" , DS . RESTSerializer . extend ( ) ) ;
902
+ let payload = {
903
+ doomsdayDevice : {
904
+ id : 1 ,
905
+ evilMinion : 2
906
+ } ,
907
+ evilMinion : {
908
+ id : 2 ,
909
+ doomsdayDevice : 1
910
+ }
911
+ } ;
912
+
913
+ let document = env . store . serializerFor ( 'doomsday-device' ) . normalizeSingleResponse ( env . store , DoomsdayDevice , payload ) ;
914
+ assert . equal ( document . data . relationships . evilMinion . data . id , 2 ) ;
915
+ assert . equal ( document . included . length , 1 ) ;
916
+ assert . deepEqual ( document . included [ 0 ] , {
917
+ attributes : { } ,
918
+ id : '2' ,
919
+ type : 'evil-minion' ,
920
+ relationships : {
921
+ doomsdayDevice : {
922
+ data : {
923
+ id : '1' ,
924
+ type : 'doomsday-device'
925
+ }
926
+ }
927
+ }
928
+ } ) ;
929
+ } ) ;
930
+
931
+ // https://github.com/emberjs/data/issues/3805
932
+ test ( 'normalizes sideloaded single record so that it sideloads correctly - hasMany - GH-3805' , function ( assert ) {
933
+ env . registry . register ( "serializer:home-planet" , DS . RESTSerializer . extend ( ) ) ;
934
+ let payload = {
935
+ homePlanet : {
936
+ id : 1 ,
937
+ superVillains : [ 2 ]
938
+ } ,
939
+ superVillain : {
940
+ id : 2 ,
941
+ homePlanet : 1
942
+ }
943
+ } ;
944
+
945
+ let document = env . store . serializerFor ( 'home-planet' ) . normalizeSingleResponse ( env . store , HomePlanet , payload ) ;
946
+
947
+ assert . equal ( document . data . relationships . superVillains . data . length , 1 ) ;
948
+ assert . equal ( document . data . relationships . superVillains . data [ 0 ] . id , 2 ) ;
949
+ assert . equal ( document . included . length , 1 ) ;
950
+ assert . deepEqual ( document . included [ 0 ] , {
951
+ attributes : { } ,
952
+ id : '2' ,
953
+ type : 'super-villain' ,
954
+ relationships : {
955
+ homePlanet : {
956
+ data : {
957
+ id : '1' ,
958
+ type : 'home-planet'
959
+ }
960
+ }
961
+ }
962
+ } ) ;
963
+ } ) ;
0 commit comments