Ticket #5743: dojo_1.0.X_dojo.data.ItemFileWriteStore_20080204.patch
| File dojo_1.0.X_dojo.data.ItemFileWriteStore_20080204.patch, 9.5 kB (added by jaredj, 11 months ago) |
|---|
-
tests/data/countries_references.json
1 { 'identifier': 'name', 2 'label': 'name', 3 'items': [ 4 { 'name':'Africa', 'type':'continent', 5 'children':[{'_reference':'Egypt'}, {'_reference':'Kenya'}, {'_reference':'Sudan'}] }, 6 { 'name':'Egypt', 'type':'country' }, 7 { 'name':'Kenya', 'type':'country', 8 'children':[{'_reference':'Nairobi'}, {'_reference':'Mombasa'}] }, 9 { 'name':'Nairobi', 'type':'city' }, 10 { 'name':'Mombasa', 'type':'city' }, 11 { 'name':'Sudan', 'type':'country', 12 'children':{'_reference':'Khartoum'} }, 13 { 'name':'Khartoum', 'type':'city' }, 14 { 'name':'Asia', 'type':'continent', 15 'children':[{'_reference':'China'}, {'_reference':'India'}, {'_reference':'Russia'}, {'_reference':'Mongolia'}] }, 16 { 'name':'China', 'type':'country' }, 17 { 'name':'India', 'type':'country' }, 18 { 'name':'Russia', 'type':'country' }, 19 { 'name':'Mongolia', 'type':'country' }, 20 { 'name':'Australia', 'type':'continent', 'population':'21 million', 21 'children':{'_reference':'Commonwealth of Australia'}}, 22 { 'name':'Commonwealth of Australia', 'type':'country', 'population':'21 million'}, 23 { 'name':'Europe', 'type':'continent', 24 'children':[{'_reference':'Germany'}, {'_reference':'France'}, {'_reference':'Spain'}, {'_reference':'Italy'}] }, 25 { 'name':'Germany', 'type':'country' }, 26 { 'name':'France', 'type':'country' }, 27 { 'name':'Spain', 'type':'country' }, 28 { 'name':'Italy', 'type':'country' }, 29 { 'name':'North America', 'type':'continent', 30 'children':[{'_reference':'Mexico'}, {'_reference':'Canada'}, {'_reference':'United States of America'}] }, 31 { 'name':'Mexico', 'type':'country', 'population':'108 million', area:'1,972,550 sq km', 32 'children':[{'_reference':'Mexico City'}, {'_reference':'Guadalajara'}] }, 33 { 'name':'Mexico City', 'type':'city', 'population':'19 million', 'timezone':'-6 UTC'}, 34 { 'name':'Guadalajara', 'type':'city', 'population':'4 million', 'timezone':'-6 UTC' }, 35 { 'name':'Canada', 'type':'country', 'population':'33 million', area:'9,984,670 sq km', 36 'children':[{'_reference':'Ottawa'}, {'_reference':'Toronto'}] }, 37 { 'name':'Ottawa', 'type':'city', 'population':'0.9 million', 'timezone':'-5 UTC'}, 38 { 'name':'Toronto', 'type':'city', 'population':'2.5 million', 'timezone':'-5 UTC' }, 39 { 'name':'United States of America', 'type':'country' }, 40 { 'name':'South America', 'type':'continent', 41 'children':[{'_reference':'Brazil'}, {'_reference':'Argentina'}] }, 42 { 'name':'Brazil', 'type':'country', 'population':'186 million' }, 43 { 'name':'Argentina', 'type':'country', 'population':'40 million' } 44 ]} -
tests/data/readOnlyItemFileTestTemplates.js
168 168 } 169 169 }; 170 170 } 171 }else if(name === "countries_references"){ 172 if(dojo.isBrowser){ 173 data = {url: dojo.moduleUrl("tests", "data/countries_references.json").toString() }; 174 }else{ 175 data = {data: { identifier: 'name', 176 label: 'name', 177 items: [ 178 { name:'Africa', type:'continent', 179 children:[{_reference:'Egypt'}, {_reference:'Kenya'}, {_reference:'Sudan'}] }, 180 { name:'Egypt', type:'country' }, 181 { name:'Kenya', type:'country', 182 children:[{_reference:'Nairobi'}, {_reference:'Mombasa'}] }, 183 { name:'Nairobi', type:'city' }, 184 { name:'Mombasa', type:'city' }, 185 { name:'Sudan', type:'country', 186 children:{_reference:'Khartoum'} }, 187 { name:'Khartoum', type:'city' }, 188 { name:'Asia', type:'continent', 189 children:[{_reference:'China'}, {_reference:'India'}, {_reference:'Russia'}, {_reference:'Mongolia'}] }, 190 { name:'China', type:'country' }, 191 { name:'India', type:'country' }, 192 { name:'Russia', type:'country' }, 193 { name:'Mongolia', type:'country' }, 194 { name:'Australia', type:'continent', population:'21 million', 195 children:{_reference:'Commonwealth of Australia'}}, 196 { name:'Commonwealth of Australia', type:'country', population:'21 million'}, 197 { name:'Europe', type:'continent', 198 children:[{_reference:'Germany'}, {_reference:'France'}, {_reference:'Spain'}, {_reference:'Italy'}] }, 199 { name:'Germany', type:'country' }, 200 { name:'France', type:'country' }, 201 { name:'Spain', type:'country' }, 202 { name:'Italy', type:'country' }, 203 { name:'North America', type:'continent', 204 children:[{_reference:'Mexico'}, {_reference:'Canada'}, {_reference:'United States of America'}] }, 205 { name:'Mexico', type:'country', population:'108 million', area:'1,972,550 sq km', 206 children:[{_reference:'Mexico City'}, {_reference:'Guadalajara'}] }, 207 { name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'}, 208 { name:'Guadalajara', type:'city', population:'4 million', timezone:'-6 UTC' }, 209 { name:'Canada', type:'country', population:'33 million', area:'9,984,670 sq km', 210 children:[{_reference:'Ottawa'}, {_reference:'Toronto'}] }, 211 { name:'Ottawa', type:'city', population:'0.9 million', timezone:'-5 UTC'}, 212 { name:'Toronto', type:'city', population:'2.5 million', timezone:'-5 UTC' }, 213 { name:'United States of America', type:'country' }, 214 { name:'South America', type:'continent', 215 children:[{_reference:'Brazil'}, {_reference:'Argentina'}] }, 216 { name:'Brazil', type:'country', population:'186 million' }, 217 { name:'Argentina', type:'country', population:'40 million' } 218 ] 219 } 220 }; 221 } 171 222 } 172 223 return data; 173 224 }; -
tests/data/ItemFileWriteStore.js
380 380 store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError}); 381 381 return deferred; //Object 382 382 }, 383 function testWriteAPI_deleteAndModifyMultipleItemsAndRevert(){ 384 // summary: 385 // Simple test to verify that a flow of deleting items and modifying items does not damage the internal structure. 386 // Created for tracker bug: #5743 387 // description: 388 // Simple test to verify that a flow of deleting items and modifying items does not damage the internal structure. 389 // Created for tracker bug: #5743 390 391 var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_references")); 392 393 var deferred = new doh.Deferred(); 394 var passed = true; 395 function onError(error, request){ 396 deferred.errback(error); 397 doh.assertTrue(false); 398 } 399 function onItem(item, request){ 400 //Save off the located item, then locate another one (peer to Egypt) 401 doh.assertTrue(store.isItem(item)); 402 var egypt = item; 403 404 function onItem2(item, request){ 405 doh.assertTrue(store.isItem(item)); 406 var nairobi = item; 407 408 function onItem3(item, request){ 409 doh.assertTrue(store.isItem(item)); 410 var kenya = item; 411 412 //Remove the reference to nairobi before we delete the Narobi item. 413 //Basically, force Kenya to be modified top-level. Since the 414 //current impl doesn't 415 var children = store.getValues(kenya, "children"); 416 var newChildren = []; 417 var i; 418 for(i = 0; i < children.length; i++){ 419 var value = children[i]; 420 if(store.isItem(value)){ 421 if (store.getIdentity(value) != store.getIdentity(nairobi)){ 422 newChildren.push(value); 423 } 424 }else{ 425 newChildren.push(value); 426 } 427 } 428 store.setValues(kenya, "children", newChildren); 429 store.deleteItem(nairobi); 430 store.deleteItem(egypt); 431 432 try{ 433 //Revert, then do a fetch. If the internals have been damaged, this will generally 434 //cause onError to fire instead of onComplete. 435 store.revert(); 436 function onComplete(items, request){ 437 deferred.callback(true); 438 } 439 store.fetch({query: {name: "*"}, start: 0, count: 20, onComplete: onComplete, onError: onError}); 440 }catch(e){ 441 deferred.errback(e) 442 } 443 } 444 store.fetchItemByIdentity({identity: "Kenya", onError: onError, onItem: onItem3}); 445 } 446 store.fetchItemByIdentity({identity: "Nairobi", onError: onError, onItem: onItem2}); 447 } 448 store.fetchItemByIdentity({identity: "Egypt", onError: onError, onItem: onItem}); 449 return deferred; 450 }, 383 451 function testWriteAPI_save(){ 384 452 // summary: 385 453 // Simple test of the save API -
data/ItemFileWriteStore.js
462 462 this._arrayOfAllItems[arrayIndex] = originalItem; 463 463 464 464 if(modifiedItem[this._rootItemPropName]){ 465 arrayIndex = modifiedItem[this._itemNumPropName]; 466 this._arrayOfTopLevelItems[arrayIndex] = originalItem; 465 var i; 466 for (i = 0; i < this._arrayOfTopLevelItems.length; i++) { 467 var possibleMatch = this._arrayOfTopLevelItems[i]; 468 if (this.getIdentity(possibleMatch) == identity){ 469 this._arrayOfTopLevelItems[i] = originalItem; 470 break; 471 } 472 } 467 473 } 468 474 if(this._itemsByIdentity){ 469 475 this._itemsByIdentity[identity] = originalItem;