Changeset 12277

Show
Ignore:
Timestamp:
02/04/08 09:09:27 (11 months ago)
Author:
jaredj
Message:

Backport of fix to revert code. fixes #5743 \!strict

Location:
branches/1.0/dojo/trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/dojo/trunk/data/ItemFileWriteStore.js

    r11813 r12277  
    463463                         
    464464                        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                                } 
    467473                        } 
    468474                        if(this._itemsByIdentity){ 
  • branches/1.0/dojo/trunk/tests/data/ItemFileWriteStore.js

    r11813 r12277  
    380380                        store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError}); 
    381381                        return deferred; //Object 
     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; 
    382450                }, 
    383451                function testWriteAPI_save(){ 
  • branches/1.0/dojo/trunk/tests/data/readOnlyItemFileTestTemplates.js

    r11281 r12277  
    169169                                        }; 
    170170                } 
     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                } 
    171222        } 
    172223        return data;