{"action":"created","issue":{"url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/1","labels_url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/1/comments","events_url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/1/events","html_url":"https://github.com/CampbellSoftwareSolutions/mongoose-id-validator/issues/1","id":62512170,"number":1,"title":"MissingSchemaError in Mocha Tests","user":{"login":"c1moore","id":6350063,"avatar_url":"https://avatars.githubusercontent.com/u/6350063?v=3","gravatar_id":"","url":"https://api.github.com/users/c1moore","html_url":"https://github.com/c1moore","followers_url":"https://api.github.com/users/c1moore/followers","following_url":"https://api.github.com/users/c1moore/following{/other_user}","gists_url":"https://api.github.com/users/c1moore/gists{/gist_id}","starred_url":"https://api.github.com/users/c1moore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c1moore/subscriptions","organizations_url":"https://api.github.com/users/c1moore/orgs","repos_url":"https://api.github.com/users/c1moore/repos","events_url":"https://api.github.com/users/c1moore/events{/privacy}","received_events_url":"https://api.github.com/users/c1moore/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-17T20:39:09Z","updated_at":"2015-03-18T13:28:19Z","closed_at":null,"body":"I am trying to run some Mocha tests that all passed a few months ago, but they are all failing now.  I have narrowed the problem down to mongoose-id-validator, which is throwing a MissingSchemaError for a schema I have confirmed is loaded.\r\n\r\nHere is a simplified version of my test.  The user schema references the `_id` field of event schema and when I attempt to save the user schema, the MissingSchemaError is thrown:\r\n```\r\nvar should = require('should'),\r\n\tmongoose = require('mongoose');\r\n\r\nconsole.log(mongoose.modelNames());\r\nconsole.log(mongoose.model('Event').schema);\r\n\r\nvar\tEvnt = mongoose.model('Event'),\r\n\tUser = mongoose.model('User'),\r\n\tAttendees = mongoose.model('Attendees');\r\n\r\nvar user, evnt;\r\n\r\ndescribe(\"Model Unit Tests:\", function() {\r\n     before(function(done) {\r\n          evnt = new Evnt({\r\n               //Event definition\r\n          });\r\n\r\n          evnt.save(function() {\r\n               user = new User({\r\n                    //User definition\r\n               });\r\n\r\n               user.save(function() {\r\n                    //MissingSchemaError thrown for model Event.\r\n               });\r\n          });\r\n     });\r\n```\r\n\r\nThe result of the `console.log(mongoose.modelNames())` is:\r\n```\r\n[ 'Attendees', 'Candidate', 'Comment', 'Event', 'User' ]\r\n```\r\n\r\nThe result of the `console.log(mongoose.model('Event').schema)` is:\r\n```\r\n{ paths: \r\n   { name: \r\n      { enumValues: [],\r\n        regExp: null,\r\n        path: 'name',\r\n        instance: 'String',\r\n        validators: [Object],\r\n        setters: [Object],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null },\r\n     start_date: \r\n      { path: 'start_date',\r\n        instance: 'Number',\r\n        validators: [Object],\r\n        setters: [],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null },\r\n     end_date: \r\n      { path: 'end_date',\r\n        instance: 'Number',\r\n        validators: [Object],\r\n        setters: [],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null },\r\n     location: \r\n      { enumValues: [],\r\n        regExp: null,\r\n        path: 'location',\r\n        instance: 'String',\r\n        validators: [Object],\r\n        setters: [Object],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null },\r\n     schedule: \r\n      { enumValues: [],\r\n        regExp: null,\r\n        path: 'schedule',\r\n        instance: 'String',\r\n        validators: [],\r\n        setters: [Object],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null,\r\n        defaultValue: 'No schedule specified' },\r\n     _id: \r\n      { path: '_id',\r\n        instance: 'ObjectID',\r\n        validators: [],\r\n        setters: [Object],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null,\r\n        defaultValue: [Function: defaultId] },\r\n     __v: \r\n      { path: '__v',\r\n        instance: 'Number',\r\n        validators: [],\r\n        setters: [],\r\n        getters: [],\r\n        options: [Object],\r\n        _index: null } },\r\n  subpaths: {},\r\n  virtuals: { id: { path: 'id', getters: [Object], setters: [], options: {} } },\r\n  nested: {},\r\n  inherits: {},\r\n  callQueue: [ [ 'pre', [Object] ] ],\r\n  _indexes: [ [ [Object], [Object] ] ],\r\n  methods: {},\r\n  statics: {},\r\n  tree: \r\n   { name: { validate: [Object], trim: true, type: [Function: String] },\r\n     start_date: { validate: [Object], type: [Function: Number] },\r\n     end_date: { validate: [Object], type: [Function: Number] },\r\n     location: { validate: [Object], trim: true, type: [Function: String] },\r\n     schedule: \r\n      { default: 'No schedule specified',\r\n        trim: true,\r\n        type: [Function: String] },\r\n     _id: { auto: true, type: [Function: ObjectId] },\r\n     id: { path: 'id', getters: [Object], setters: [], options: {} },\r\n     __v: [Function: Number] },\r\n  _requiredpaths: undefined,\r\n  discriminatorMapping: undefined,\r\n  _indexedpaths: undefined,\r\n  options: \r\n   { id: true,\r\n     noVirtualId: false,\r\n     _id: true,\r\n     noId: false,\r\n     read: null,\r\n     shardKey: null,\r\n     autoIndex: true,\r\n     minimize: true,\r\n     discriminatorKey: '__t',\r\n     versionKey: '__v',\r\n     capped: false,\r\n     bufferCommands: true,\r\n     strict: true,\r\n     pluralization: true },\r\n  _events: {} }\r\n```\r\nObviously the schema is defined before the user model is saved.  Here is the error message I receive:\r\n```\r\n  1) Model Unit Tests: \"before all\" hook:\r\n     Uncaught MissingSchemaError: Schema hasn't been registered for model \"Event\".\r\nUse mongoose.model(name, schema)\r\n      at Mongoose.model (/home/c1moore/frankrs/node_modules/mongoose-id-validator/node_modules/mongoose/lib/index.js:323:13)\r\n      at validateId (/home/c1moore/frankrs/node_modules/mongoose-id-validator/lib/id-validator.js:55:29)\r\n      at EmbeddedDocument.<anonymous> (/home/c1moore/frankrs/node_modules/mongoose-id-validator/lib/id-validator.js:33:17)\r\n      at /home/c1moore/frankrs/node_modules/mongoose/lib/schematype.js:623:19\r\n      at Array.forEach (native)\r\n      at ObjectId.SchemaType.doValidate (/home/c1moore/frankrs/node_modules/mongoose/lib/schematype.js:614:19)\r\n      at /home/c1moore/frankrs/node_modules/mongoose/lib/document.js:974:9\r\n      at process._tickDomainCallback (node.js:486:13)\r\n```"},"comment":{"url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/comments/82970397","html_url":"https://github.com/CampbellSoftwareSolutions/mongoose-id-validator/issues/1#issuecomment-82970397","issue_url":"https://api.github.com/repos/CampbellSoftwareSolutions/mongoose-id-validator/issues/1","id":82970397,"user":{"login":"c1moore","id":6350063,"avatar_url":"https://avatars.githubusercontent.com/u/6350063?v=3","gravatar_id":"","url":"https://api.github.com/users/c1moore","html_url":"https://github.com/c1moore","followers_url":"https://api.github.com/users/c1moore/followers","following_url":"https://api.github.com/users/c1moore/following{/other_user}","gists_url":"https://api.github.com/users/c1moore/gists{/gist_id}","starred_url":"https://api.github.com/users/c1moore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c1moore/subscriptions","organizations_url":"https://api.github.com/users/c1moore/orgs","repos_url":"https://api.github.com/users/c1moore/repos","events_url":"https://api.github.com/users/c1moore/events{/privacy}","received_events_url":"https://api.github.com/users/c1moore/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T13:28:19Z","updated_at":"2015-03-18T13:28:19Z","body":"Thank you for your suggestions.  I will work on making these changes, but I do not believe these to be the main issue at the time.  If you forked the project you must run `npm update` before running `grunt test`.  After updating all npm packages, I receive the error above and *no* other test cases run (hence I do not see the same errors you are mentioning above).\r\n\r\nI definitely agree that the changes you mentioned need to be made, but I still believe there may be a problem with **mongoose-id-validator** or something else that I am missing related to **mongoose-id-validator**.  The `MissingSchemaError` appears to always be thrown on the `Event` schema, even when running other tests (i.e.: comment out/delete the Attendees integration tests file and run `grunt test` again and you will receive the same error for the `Event` schema).  If you did fork the project, I would appreciate any suggestions you may have for getting past this error."}}