Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firebase-collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ <h4>[[dinosaur.__firebaseKey__]]</h4>

query = this.query.ref().push();
query.set(data);
if (typeof data == 'object') {
data.__firebaseKey__ = query.key();
}

return query;
},
Expand Down
56 changes: 55 additions & 1 deletion test/firebase-collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
});

});
});
</script>
Expand Down