Created
June 26, 2012 23:55
-
-
Save panosru/3000268 to your computer and use it in GitHub Desktop.
Cannot get defaults when retrieving only certain fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Dependencies | |
var | |
mongoose = require('mongoose'), | |
vows = require('vows'), | |
suite = vows.describe('Mongoose ' + mongoose.version + ' test issue #876'), | |
assert = require('assert'), | |
EventEmitter = require('events').EventEmitter | |
; | |
// Initialize Connection | |
mongoose.connect('mongodb://localhost/mongoose_test_issue_876'); | |
// Define Schema | |
var DemoSchema = new mongoose.Schema({ | |
name : String | |
, surname : String | |
, active : { type : Boolean, default : false } | |
}); | |
// Set Model | |
mongoose.model('Demo', DemoSchema); | |
// Get Model | |
var Demo = mongoose.model('Demo'); | |
// Create Tests | |
suite.addBatch({ | |
'Create database entry' : { | |
topic : function () { | |
var | |
promise = new EventEmitter(), | |
demo = new Demo({ name : 'Panagiotis', surname : 'Kosmidis'}) | |
; | |
demo.save(function (err) { promise.emit('success', err) }); | |
return promise; | |
}, | |
'Data stored in database' : function (topic) { | |
assert.equal(topic, null); | |
} | |
}, | |
'Retrieve data with all fields' : { | |
topic : function () { | |
var promise = new EventEmitter(); | |
Demo.findOne({ name : 'Panagiotis' }, function (err, doc) { | |
promise.emit('success', doc.active); | |
}); | |
return promise; | |
}, | |
'Active should be false' : function (topic) { | |
assert.equal(topic, false); | |
} | |
}, | |
'Retrieve data with specific fields' : { | |
topic : function () { | |
var promise = new EventEmitter(); | |
Demo.findOne({ name : 'Panagiotis' }, ['name', 'active'], function (err, doc) { | |
promise.emit('success', doc.active); | |
}); | |
return promise; | |
}, | |
'Active should be false' : function (topic) { | |
assert.equal(topic, false); | |
} | |
} | |
}).run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment