[Pkg-javascript-commits] [dojo] 03/08: Backport of fix to revert code. fixes #5743 \!strict

David Prévot taffit at moszumanska.debian.org
Mon May 11 20:11:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.0.3
in repository dojo.

commit 6523ebef3d6b5464ef8467490cbcdcaf0f3737d5
Author: Jared Jurkiewicz <jaredj at dojotoolkit.org>
Date:   Mon Feb 4 17:09:27 2008 +0000

    Backport of fix to revert code.  fixes #5743 \!strict
    
    git-svn-id: http://svn.dojotoolkit.org/src/branches/1.0/dojo/trunk@12277 560b804f-0ae3-0310-86f3-f6aa0a117693
---
 data/ItemFileWriteStore.js                  | 10 ++++-
 tests/data/ItemFileWriteStore.js            | 68 +++++++++++++++++++++++++++++
 tests/data/countries_references.json        | 44 +++++++++++++++++++
 tests/data/readOnlyItemFileTestTemplates.js | 51 ++++++++++++++++++++++
 4 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/data/ItemFileWriteStore.js b/data/ItemFileWriteStore.js
index b226225..9f87da5 100644
--- a/data/ItemFileWriteStore.js
+++ b/data/ItemFileWriteStore.js
@@ -462,8 +462,14 @@ dojo.declare("dojo.data.ItemFileWriteStore", dojo.data.ItemFileReadStore, {
 			this._arrayOfAllItems[arrayIndex] = originalItem;
 			
 			if(modifiedItem[this._rootItemPropName]){
-				arrayIndex = modifiedItem[this._itemNumPropName];
-				this._arrayOfTopLevelItems[arrayIndex] = originalItem;
+				var i;
+				for (i = 0; i < this._arrayOfTopLevelItems.length; i++) {
+					var possibleMatch = this._arrayOfTopLevelItems[i];
+					if (this.getIdentity(possibleMatch) == identity){
+						this._arrayOfTopLevelItems[i] = originalItem;
+						break;
+					}
+				}
 			}
 			if(this._itemsByIdentity){
 				this._itemsByIdentity[identity] = originalItem;
diff --git a/tests/data/ItemFileWriteStore.js b/tests/data/ItemFileWriteStore.js
index 07ab19d..88a4b00 100644
--- a/tests/data/ItemFileWriteStore.js
+++ b/tests/data/ItemFileWriteStore.js
@@ -380,6 +380,74 @@ doh.register("tests.data.ItemFileWriteStore",
 			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});
 			return deferred; //Object
 		},
+		function testWriteAPI_deleteAndModifyMultipleItemsAndRevert(){
+			//	summary: 
+			//		Simple test to verify that a flow of deleting items and modifying items does not damage the internal structure.
+			//		Created for tracker bug: #5743
+			//	description:
+			//		Simple test to verify that a flow of deleting items and modifying items does not damage the internal structure.
+			//		Created for tracker bug: #5743
+		
+			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_references"));
+
+			var deferred = new doh.Deferred();
+			var passed = true;
+			function onError(error, request){
+				deferred.errback(error);
+				doh.assertTrue(false);
+			}
+			function onItem(item, request){
+				//Save off the located item, then locate another one (peer to Egypt)
+				doh.assertTrue(store.isItem(item));
+				var egypt = item;
+
+				function onItem2(item, request){
+					doh.assertTrue(store.isItem(item));
+					var nairobi = item;
+
+					function onItem3(item, request){
+						doh.assertTrue(store.isItem(item));
+						var kenya = item;
+
+						//Remove the reference to nairobi before we delete the Narobi item.
+						//Basically, force Kenya to be modified top-level.  Since the
+						//current impl doesn't 
+						var children = store.getValues(kenya, "children");
+						var newChildren = [];
+						var i;
+						for(i = 0; i < children.length; i++){
+							var value = children[i];
+							if(store.isItem(value)){
+								if (store.getIdentity(value) != store.getIdentity(nairobi)){
+									newChildren.push(value);
+								}
+							}else{
+								newChildren.push(value);
+							}
+						}
+						store.setValues(kenya, "children", newChildren);
+						store.deleteItem(nairobi);
+						store.deleteItem(egypt);
+
+						try{
+							//Revert, then do a fetch.  If the internals have been damaged, this will generally
+							//cause onError to fire instead of onComplete.
+							store.revert();
+							function onComplete(items, request){
+								deferred.callback(true);
+							}
+							store.fetch({query: {name: "*"}, start: 0, count: 20, onComplete: onComplete, onError: onError});
+						}catch(e){
+							deferred.errback(e)
+						}
+					}
+					store.fetchItemByIdentity({identity: "Kenya", onError: onError, onItem: onItem3});
+				}
+				store.fetchItemByIdentity({identity: "Nairobi", onError: onError, onItem: onItem2});
+			}
+			store.fetchItemByIdentity({identity: "Egypt", onError: onError, onItem: onItem});
+			return deferred;
+		},
 		function testWriteAPI_save(){
 			//	summary: 
 			//		Simple test of the save API
diff --git a/tests/data/countries_references.json b/tests/data/countries_references.json
new file mode 100644
index 0000000..136f3c2
--- /dev/null
+++ b/tests/data/countries_references.json
@@ -0,0 +1,44 @@
+{ 'identifier': 'name',
+  'label': 'name',
+  'items': [
+	{ 'name':'Africa', 'type':'continent',
+		'children':[{'_reference':'Egypt'}, {'_reference':'Kenya'}, {'_reference':'Sudan'}] },
+	{ 'name':'Egypt', 'type':'country' },
+	{ 'name':'Kenya', 'type':'country',
+		 'children':[{'_reference':'Nairobi'}, {'_reference':'Mombasa'}] },
+	{ 'name':'Nairobi', 'type':'city' },
+	{ 'name':'Mombasa', 'type':'city' },
+	{ 'name':'Sudan', 'type':'country',
+		'children':{'_reference':'Khartoum'} },
+	{ 'name':'Khartoum', 'type':'city' },
+	{ 'name':'Asia', 'type':'continent',
+		'children':[{'_reference':'China'}, {'_reference':'India'}, {'_reference':'Russia'}, {'_reference':'Mongolia'}] },
+	{ 'name':'China', 'type':'country' },
+	{ 'name':'India', 'type':'country' },
+	{ 'name':'Russia', 'type':'country' },
+	{ 'name':'Mongolia', 'type':'country' },
+	{ 'name':'Australia', 'type':'continent', 'population':'21 million',
+		'children':{'_reference':'Commonwealth of Australia'}},
+	{ 'name':'Commonwealth of Australia', 'type':'country', 'population':'21 million'},
+	{ 'name':'Europe', 'type':'continent',
+		'children':[{'_reference':'Germany'}, {'_reference':'France'}, {'_reference':'Spain'}, {'_reference':'Italy'}] },
+	{ 'name':'Germany', 'type':'country' },
+	{ 'name':'France', 'type':'country' },
+	{ 'name':'Spain', 'type':'country' },
+	{ 'name':'Italy', 'type':'country' },
+	{ 'name':'North America', 'type':'continent',
+		'children':[{'_reference':'Mexico'}, {'_reference':'Canada'}, {'_reference':'United States of America'}] },
+	{ 'name':'Mexico', 'type':'country',  'population':'108 million', area:'1,972,550 sq km',
+		'children':[{'_reference':'Mexico City'}, {'_reference':'Guadalajara'}] },
+	{ 'name':'Mexico City', 'type':'city', 'population':'19 million', 'timezone':'-6 UTC'},
+	{ 'name':'Guadalajara', 'type':'city', 'population':'4 million', 'timezone':'-6 UTC' },
+	{ 'name':'Canada', 'type':'country',  'population':'33 million', area:'9,984,670 sq km',
+		'children':[{'_reference':'Ottawa'}, {'_reference':'Toronto'}] },
+	{ 'name':'Ottawa', 'type':'city', 'population':'0.9 million', 'timezone':'-5 UTC'},
+	{ 'name':'Toronto', 'type':'city', 'population':'2.5 million', 'timezone':'-5 UTC' },
+	{ 'name':'United States of America', 'type':'country' },
+	{ 'name':'South America', 'type':'continent',
+		'children':[{'_reference':'Brazil'}, {'_reference':'Argentina'}] },
+	{ 'name':'Brazil', 'type':'country', 'population':'186 million' },
+	{ 'name':'Argentina', 'type':'country', 'population':'40 million' }
+]}
diff --git a/tests/data/readOnlyItemFileTestTemplates.js b/tests/data/readOnlyItemFileTestTemplates.js
index 1ee6e6c..6821edd 100644
--- a/tests/data/readOnlyItemFileTestTemplates.js
+++ b/tests/data/readOnlyItemFileTestTemplates.js
@@ -168,6 +168,57 @@ tests.data.readOnlyItemFileTestTemplates.getTestData = function(name){
 						} 
 					};
 		}
+	}else if(name === "countries_references"){
+		if(dojo.isBrowser){
+			data = {url: dojo.moduleUrl("tests", "data/countries_references.json").toString() };
+		}else{
+			data = {data: { identifier: 'name',
+							label: 'name',
+							items: [
+								{ name:'Africa', type:'continent',
+									children:[{_reference:'Egypt'}, {_reference:'Kenya'}, {_reference:'Sudan'}] },
+								{ name:'Egypt', type:'country' },
+								{ name:'Kenya', type:'country',
+									children:[{_reference:'Nairobi'}, {_reference:'Mombasa'}] },
+								{ name:'Nairobi', type:'city' },
+								{ name:'Mombasa', type:'city' },
+								{ name:'Sudan', type:'country',
+									children:{_reference:'Khartoum'} },
+								{ name:'Khartoum', type:'city' },
+								{ name:'Asia', type:'continent',
+									children:[{_reference:'China'}, {_reference:'India'}, {_reference:'Russia'}, {_reference:'Mongolia'}] },
+								{ name:'China', type:'country' },
+								{ name:'India', type:'country' },
+								{ name:'Russia', type:'country' },
+								{ name:'Mongolia', type:'country' },
+								{ name:'Australia', type:'continent', population:'21 million',
+									children:{_reference:'Commonwealth of Australia'}},
+								{ name:'Commonwealth of Australia', type:'country', population:'21 million'},
+								{ name:'Europe', type:'continent',
+									children:[{_reference:'Germany'}, {_reference:'France'}, {_reference:'Spain'}, {_reference:'Italy'}] },
+								{ name:'Germany', type:'country' },
+								{ name:'France', type:'country' },
+								{ name:'Spain', type:'country' },
+								{ name:'Italy', type:'country' },
+								{ name:'North America', type:'continent',
+									children:[{_reference:'Mexico'}, {_reference:'Canada'}, {_reference:'United States of America'}] },
+								{ name:'Mexico', type:'country',  population:'108 million', area:'1,972,550 sq km',
+									children:[{_reference:'Mexico City'}, {_reference:'Guadalajara'}] },
+								{ name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'},
+								{ name:'Guadalajara', type:'city', population:'4 million', timezone:'-6 UTC' },
+								{ name:'Canada', type:'country',  population:'33 million', area:'9,984,670 sq km',
+									children:[{_reference:'Ottawa'}, {_reference:'Toronto'}] },
+								{ name:'Ottawa', type:'city', population:'0.9 million', timezone:'-5 UTC'},
+								{ name:'Toronto', type:'city', population:'2.5 million', timezone:'-5 UTC' },
+								{ name:'United States of America', type:'country' },
+								{ name:'South America', type:'continent',
+									children:[{_reference:'Brazil'}, {_reference:'Argentina'}] },
+								{ name:'Brazil', type:'country', population:'186 million' },
+								{ name:'Argentina', type:'country', population:'40 million' }
+							]
+						}
+					};
+		}
 	}
 	return data;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list