diff --git a/firebase-collection.html b/firebase-collection.html index 64de6f6..40dd3a6 100644 --- a/firebase-collection.html +++ b/firebase-collection.html @@ -248,6 +248,9 @@

[[dinosaur.__firebaseKey__]]

query = this.query.ref().push(); query.set(data); + if (typeof data == 'object') { + data.__firebaseKey__ = query.key(); + } return query; }, diff --git a/test/firebase-collection.html b/test/firebase-collection.html index 8aecae4..3f64770 100644 --- a/test/firebase-collection.html +++ b/test/firebase-collection.html @@ -208,7 +208,7 @@ }); }); - test('adds a new child based on local changes'); + // test('adds a new child based on local changes'); test('updates the child key in place with the new value', function(done) { var childrenKeys = []; @@ -294,6 +294,60 @@ key = localFirebase.add(data).key(); }); + + }); + + suite('syncing collections', function() { + var localFirebase; + var remoteFirebase; + + setup(function() { + firebase = fixture('SyncingCollections'); + localFirebase = firebase[0]; + remoteFirebase = firebase[1]; + // Don't need to wait since these will already be ready + // due to the previous tests + }); + + test('adds item and syncs modifications', function(done) { + var timestamp = Date.now(); + var remoteObj = {foo: timestamp}; + + waitForEvent(localFirebase, 'firebase-value').then(function() { + var localObj; + localFirebase.data.some(function(o) { + if (o.foo == timestamp) { + localObj = o; + return true; + } + }); + expect(localObj).to.be.ok; + // Modify item + var idx = remoteFirebase.data.indexOf(remoteObj); + remoteFirebase.set(['data', idx, 'foo'], ++timestamp); + localObj = null; + localFirebase.data.some(function(o) { + if (o.foo == timestamp) { + localObj = o; + return true; + } + }); + expect(localObj.foo).to.be.equal(timestamp); + // Remove item + remoteFirebase.splice('data', idx, 1); + var hasObj = localFirebase.data.some(function(o) { + return (o.foo == timestamp); + }); + expect(hasObj).to.be.false; + done(); + }).catch(function(e) { + done(e); + }); + + // Add item + remoteFirebase.push('data', remoteObj); + }); + }); });