Wallets in both formats only get listed once

This commit is contained in:
Ivan Socolsky 2014-09-24 09:39:17 -03:00
commit 48c3633ece
2 changed files with 24 additions and 17 deletions

View file

@ -258,9 +258,14 @@ Storage.prototype.getWallets2 = function(cb) {
Storage.prototype.getWallets = function(cb) { Storage.prototype.getWallets = function(cb) {
var self = this; var self = this;
self.getWallets2(function(wallets1) { self.getWallets2(function(wallets) {
self.getWallets_Old(function(wallets2) { self.getWallets_Old(function(wallets2) {
return cb(wallets1.concat(wallets2)); var ids = _.pluck(wallets, 'id');
_.each(wallets2, function(w) {
if (!_.contains(ids, w.id))
wallets.push(w);
});
return cb(wallets);
}); });
}) })
}; };

View file

@ -217,22 +217,24 @@ describe('Storage model', function() {
s.setFromObj('1', w1, function() { s.setFromObj('1', w1, function() {
s.setFromObj('2', w2, function() { s.setFromObj('2', w2, function() {
s._write('3::name', 'matias', function() { s._write('3::name', 'matias', function() {
s.setGlobal('nameFor::3', 'wallet3', function() { s._write('1::name', 'juan', function() {
s.getWallets(function(ws) { s.setGlobal('nameFor::3', 'wallet3', function() {
ws.length.should.equal(3); s.getWallets(function(ws) {
ws[0].should.deep.equal({ ws.length.should.equal(3);
id: '1', ws[0].should.deep.equal({
name: 'wallet1', id: '1',
name: 'wallet1',
});
ws[1].should.deep.equal({
id: '2',
name: undefined
});
ws[2].should.deep.equal({
id: '3',
name: 'wallet3',
});
done();
}); });
ws[1].should.deep.equal({
id: '2',
name: undefined
});
ws[2].should.deep.equal({
id: '3',
name: 'wallet3',
});
done();
}); });
}); });
}) })