@@ -840,8 +840,74 @@ describe("Sync", function() {
840
840
} ) ;
841
841
} ) ;
842
842
843
- describe ( "#autoMerge" , function ( ) {
844
- describe ( "when node was updated" , function ( ) {
843
+ describe . only ( "#autoMerge" , function ( ) {
844
+ describe ( "new node" , function ( ) {
845
+ beforeEach ( function ( ) {
846
+ this . node = {
847
+ path : "foo" ,
848
+ common : { } ,
849
+ remote : { body : "new value" , contentType : "new content-type" , revision : "remote" }
850
+ } ;
851
+ } ) ;
852
+
853
+ it ( "emits a 'change' event" , function ( done ) {
854
+ this . rs . local . emitChange = function ( changeEvent ) {
855
+ expect ( changeEvent ) . to . deep . equal ( {
856
+ origin : "remote" ,
857
+ path : "foo" ,
858
+ newValue : "new value" ,
859
+ oldValue : undefined ,
860
+ newContentType : "new content-type" ,
861
+ oldContentType : undefined
862
+ } ) ;
863
+ done ( ) ;
864
+ } ;
865
+
866
+ this . rs . sync . autoMerge ( this . node ) ;
867
+ } ) ;
868
+
869
+ it ( "merges the node items" , function ( ) {
870
+ expect ( this . rs . sync . autoMerge ( this . node ) ) . to . deep . equal ( {
871
+ path : "foo" ,
872
+ common : { body : "new value" , contentType : "new content-type" , revision : "remote" }
873
+ } ) ;
874
+ } ) ;
875
+
876
+ describe ( "with zero-length body" , function ( ) {
877
+ beforeEach ( function ( ) {
878
+ this . node = {
879
+ path : "foo" ,
880
+ common : { } ,
881
+ remote : { body : "" , contentType : "new content-type" , revision : "remote" }
882
+ } ;
883
+ } ) ;
884
+
885
+ it ( "emits a 'change' event" , function ( done ) {
886
+ this . rs . local . emitChange = function ( changeEvent ) {
887
+ expect ( changeEvent ) . to . deep . equal ( {
888
+ origin : "remote" ,
889
+ path : "foo" ,
890
+ newValue : "" ,
891
+ oldValue : undefined ,
892
+ newContentType : "new content-type" ,
893
+ oldContentType : undefined
894
+ } ) ;
895
+ done ( ) ;
896
+ } ;
897
+
898
+ this . rs . sync . autoMerge ( this . node ) ;
899
+ } ) ;
900
+
901
+ it ( "merges the node items" , function ( ) {
902
+ expect ( this . rs . sync . autoMerge ( this . node ) ) . to . deep . equal ( {
903
+ path : "foo" ,
904
+ common : { body : "" , contentType : "new content-type" , revision : "remote" }
905
+ } ) ;
906
+ } ) ;
907
+ } ) ;
908
+ } ) ;
909
+
910
+ describe ( "updated node" , function ( ) {
845
911
beforeEach ( function ( ) {
846
912
this . node = {
847
913
path : "foo" ,
@@ -872,9 +938,42 @@ describe("Sync", function() {
872
938
common : { body : "new value" , contentType : "new content-type" , revision : "remote" }
873
939
} ) ;
874
940
} ) ;
941
+
942
+ describe ( "with zero-length body" , function ( ) {
943
+ beforeEach ( function ( ) {
944
+ this . node = {
945
+ path : "foo" ,
946
+ common : { body : "old value" , contentType : "old content-type" , revision : "common" } ,
947
+ remote : { body : "" , contentType : "new content-type" , revision : "remote" }
948
+ } ;
949
+ } ) ;
950
+
951
+ it ( "emits a 'change' event" , function ( done ) {
952
+ this . rs . local . emitChange = function ( changeEvent ) {
953
+ expect ( changeEvent ) . to . deep . equal ( {
954
+ origin : "remote" ,
955
+ path : "foo" ,
956
+ newValue : "" ,
957
+ oldValue : "old value" ,
958
+ newContentType : "new content-type" ,
959
+ oldContentType : "old content-type"
960
+ } ) ;
961
+ done ( ) ;
962
+ } ;
963
+
964
+ this . rs . sync . autoMerge ( this . node ) ;
965
+ } ) ;
966
+
967
+ it ( "merges the node items" , function ( ) {
968
+ expect ( this . rs . sync . autoMerge ( this . node ) ) . to . deep . equal ( {
969
+ path : "foo" ,
970
+ common : { body : "" , contentType : "new content-type" , revision : "remote" }
971
+ } ) ;
972
+ } ) ;
973
+ } ) ;
875
974
} ) ;
876
975
877
- describe ( "when node was deleted " , function ( ) {
976
+ describe ( "deleted node" , function ( ) {
878
977
describe ( "with node cached before" , function ( ) {
879
978
beforeEach ( function ( ) {
880
979
this . node = {
0 commit comments