File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -390,7 +390,9 @@ DatastoreRequest.prototype.save = function(entities, callback) {
390390
391391 if ( Array . isArray ( entityObject . data ) ) {
392392 ent . property = entityObject . data . map ( function ( data ) {
393- data . value = entity . valueToProperty ( data . value ) ;
393+ data = extend ( true , { } , data , {
394+ value : entity . valueToProperty ( data . value )
395+ } ) ;
394396
395397 if ( is . boolean ( data . excludeFromIndexes ) ) {
396398 var indexed = ! data . excludeFromIndexes ;
Original file line number Diff line number Diff line change @@ -455,6 +455,29 @@ describe('Request', function() {
455455 ] , done ) ;
456456 } ) ;
457457
458+ it ( 'should not alter the provided data object' , function ( done ) {
459+ var data = [
460+ {
461+ name : 'test-name' ,
462+ value : {
463+ a : 'b' ,
464+ c : [ 1 , 2 , 3 ]
465+ } ,
466+ indexed : false
467+ }
468+ ] ;
469+ var expectedData = extend ( true , { } , data ) ;
470+
471+ request . makeReq_ = function ( method , req ) {
472+ // By the time the request is made, the original object has already been
473+ // transformed into a raw request.
474+ assert . deepEqual ( data , expectedData ) ;
475+ done ( ) ;
476+ } ;
477+
478+ request . save ( { key : key , data : data } , assert . ifError ) ;
479+ } ) ;
480+
458481 it ( 'should return apiResponse in callback' , function ( done ) {
459482 var key = new entity . Key ( { namespace : 'ns' , path : [ 'Company' ] } ) ;
460483 var mockCommitResponse = {
You can’t perform that action at this time.
0 commit comments