Skip to content

Commit

Permalink
Fix Automattic#2070: update to mongodb driver 1.4.4 (js-bson 0.2.8) f…
Browse files Browse the repository at this point in the history
…or objectid fix
  • Loading branch information
vkarpov15 committed May 16, 2014
1 parent 7c27407 commit 3455607
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
, "keywords": ["mongodb", "document", "model", "schema", "database", "odm", "data", "datastore", "query", "nosql", "orm", "db"]
, "dependencies": {
"hooks": "0.3.2"
, "mongodb": "1.4.3"
, "mongodb": "1.4.4"
, "ms": "0.1.0"
, "sliced": "0.0.5"
, "muri": "0.3.1"
Expand All @@ -27,6 +27,7 @@
, "benchmark" : "1.0.0"
, "open": "0.0.3"
, "async": "0.2.5"
, "underscore": "1.5.2"
}
, "directories": { "lib": "./lib/mongoose" }
, "scripts": { "test": "make test" }
Expand Down
44 changes: 43 additions & 1 deletion test/model.findAndUpdateOne.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ var start = require('./common')
, mongoose = start.mongoose
, random = require('../lib/utils').random
, Query = require('../lib/query')
, Utils = require('../lib/utils')
, Schema = mongoose.Schema
, SchemaType = mongoose.SchemaType
, ObjectId = Schema.Types.ObjectId
, DocumentObjectId = mongoose.Types.ObjectId
, DocumentArray = mongoose.Types.DocumentArray
, EmbeddedDocument = mongoose.Types.Embedded
, MongooseArray = mongoose.Types.Array
, MongooseError = mongoose.Error;
, MongooseError = mongoose.Error
, _ = require('underscore');

/**
* Setup.
Expand Down Expand Up @@ -830,4 +832,44 @@ describe('model: findByIdAndUpdate:', function(){
});
});
});

it('can do deep equals on object id after findOneAndUpdate (gh-2070)', function(done) {
var db = start();

var accountSchema = Schema({
name: String,
contacts: [{
account: { type: Schema.Types.ObjectId, ref: 'Account'},
name: String
}]
});

var Account = db.model('2070', accountSchema);

var a1 = new Account({ name: 'parent' });
var a2 = new Account({ name: 'child' });

a1.save(function(error, a1) {
assert.ifError(error);
a2.save(function(error, a2) {
assert.ifError(error);
Account.findOneAndUpdate(
{ name: 'parent' },
{ $push: { contacts: { account: a2._id, name: 'child' } } },
{ 'new': true },
function(error, doc) {
assert.ifError(error);
assert.ok(Utils.deepEqual(doc.contacts[0].account, a2._id));
assert.ok(_.isEqual(doc.contacts[0].account, a2._id));

Account.findOne({ name : 'parent' }, function(error, doc) {
assert.ifError(error);
assert.ok(Utils.deepEqual(doc.contacts[0].account, a2._id));
assert.ok(_.isEqual(doc.contacts[0].account, a2._id));
done();
});
});
});
});
});
})

0 comments on commit 3455607

Please sign in to comment.