Permalink
Browse files

more addToSet tests

  • Loading branch information...
1 parent 45af0a4 commit eec5355bf9b0658cc36780c26ef7ac04f691836e @aheckmann aheckmann committed Oct 18, 2011
Showing with 45 additions and 2 deletions.
  1. +45 −2 test/types.array.test.js
View
@@ -277,7 +277,6 @@ module.exports = {
m.save(function (err) {
should.strictEqual(null, err);
M.findById(m, function (err, m) {
- db.close();
should.strictEqual(null, err);
m.num.length.should.equal(5);
@@ -316,13 +315,57 @@ module.exports = {
m.str.length.should.equal(6);
m.id.addToSet(id2, id3, id4);
m.id.length.should.equal(4);
+
m.doc.$addToSet(m.doc[0], { name: '8bit' });
m.doc.length.should.equal(4);
m.doc.$addToSet({ name: 'Waltz', arr: [1] }, m.doc[0]);
m.doc.length.should.equal(4);
+
m.date.$addToSet(d1, d3, d4);
- m.date.length.should.equal(3);
+ m.date.length.should.equal(4);
+
+ m.save(function (err) {
+ should.strictEqual(null, err);
+ M.findById(m, function (err, m) {
+ db.close();
+ should.strictEqual(null, err);
+
+ m.num.length.should.equal(6);
+ (~m.num.indexOf(1)).should.be.ok;
+ (~m.num.indexOf(2)).should.be.ok;
+ (~m.num.indexOf(3)).should.be.ok;
+ (~m.num.indexOf(4)).should.be.ok;
+ (~m.num.indexOf(5)).should.be.ok;
+ (~m.num.indexOf(6)).should.be.ok;
+
+ m.str.length.should.equal(6);
+ (~m.str.indexOf('one')).should.be.ok;
+ (~m.str.indexOf('two')).should.be.ok;
+ (~m.str.indexOf('tres')).should.be.ok;
+ (~m.str.indexOf('four')).should.be.ok;
+ (~m.str.indexOf('five')).should.be.ok;
+ (~m.str.indexOf('six')).should.be.ok;
+
+ m.id.length.should.equal(4);
+ (~m.id.indexOf(id1)).should.be.ok;
+ (~m.id.indexOf(id2)).should.be.ok;
+ (~m.id.indexOf(id3)).should.be.ok;
+ (~m.id.indexOf(id4)).should.be.ok;
+
+ m.date.length.should.equal(4);
+ (~m.date.indexOf(d1.toString())).should.be.ok;
+ (~m.date.indexOf(d2.toString())).should.be.ok;
+ (~m.date.indexOf(d3.toString())).should.be.ok;
+ (~m.date.indexOf(d4.toString())).should.be.ok;
+
+ m.doc.length.should.equal(4);
+ m.doc.some(function(v){return v.name === 'Waltz'}).should.be.ok
+ m.doc.some(function(v){return v.name === 'Dubstep'}).should.be.ok
+ m.doc.some(function(v){return v.name === 'Polka'}).should.be.ok
+ m.doc.some(function(v){return v.name === '8bit'}).should.be.ok
+ });
+ });
});
});
}

0 comments on commit eec5355

Please sign in to comment.