@@ -12,6 +12,7 @@ var QUnit = require("steal-qunit");
1212var assign = require ( "can-reflect" ) . assignMap ;
1313var canDev = require ( 'can-log/dev/dev' ) ;
1414var QueryLogic = require ( "can-query-logic" ) ;
15+ var canReflect = require ( "can-reflect" ) ;
1516
1617QUnit . module ( "can-connect/real-time" , { } ) ;
1718
@@ -583,3 +584,72 @@ QUnit.test("instances should be removed from 'length-bound' lists when destroyed
583584 done ( ) ;
584585 } ) ;
585586} ) ;
587+
588+ QUnit . test ( "real-time doesn't handle updates when the id doesn't change (#436)" , function ( assert ) {
589+ var done = assert . async ( ) ;
590+ assert . expect ( 1 ) ;
591+
592+ var todos = [ {
593+ name : "test the store" ,
594+ id : "def"
595+ } , {
596+ name : "rock the house" ,
597+ id : "ghi"
598+ } ] ;
599+ var connection = connect ( [
600+ function ( ) {
601+ return {
602+ list : function ( items ) {
603+ var list = new DefineList ( items . data ) ;
604+ // simulate the can-connet/can/map/map behaviour
605+ // adding the list to the listStore
606+ connection . addListReference ( list , { } ) ;
607+ return list ;
608+ } ,
609+ getListData : function ( ) {
610+ return Promise . resolve ( todos ) ;
611+ } ,
612+ destroyData : function ( ) {
613+ // simulate an empty object response from server
614+ return Promise . resolve ( { } ) ;
615+ } ,
616+ updateData : function ( data ) {
617+ return Promise . resolve ( canReflect . serialize ( data ) ) ;
618+ }
619+ } ;
620+ } ,
621+ dataCallbacks ,
622+ realTime ,
623+ constructor ,
624+ constructorStore
625+ ] , {
626+ queryLogic : new QueryLogic ( {
627+ identity : [ "id" ]
628+ } )
629+ } ) ;
630+
631+ connection . getList ( { } ) . then ( function ( list ) {
632+ list . on ( "length" , function ( ) {
633+ assert . ok ( false , "Length should not change" ) ;
634+ } ) ;
635+ connection . save ( list [ 0 ] ) ;
636+ return list ;
637+ } ) . then ( function ( list ) {
638+ list . off ( "length" ) ;
639+ list . on ( "length" , function ( ) {
640+ assert . ok ( true , "Length should change when adding item in position 0" ) ;
641+ } ) ;
642+ return connection . save ( {
643+ name : "go to sleep" ,
644+ id : "abc"
645+ } ) ;
646+ } ) . then ( function ( ) {
647+ done ( ) ;
648+ } , function ( err ) {
649+ setTimeout ( function ( ) {
650+ throw err ;
651+ } , 1 ) ;
652+ done ( ) ;
653+ } )
654+
655+ } ) ;
0 commit comments