diff --git a/lib/utils.js b/lib/utils.js index accdcbf8e40..f35c488f31f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -54,6 +54,7 @@ exports.pluralization = [ [/([m|l])ouse$/gi, '$1ice'], [/(quiz)$/gi, '$1zes'], [/s$/gi, 's'], + [/([^a-z])$/, '$1'], [/$/gi, 's'] ]; var rules = exports.pluralization; diff --git a/test/gh-1703.test.js b/test/gh-1703.test.js new file mode 100644 index 00000000000..42c0710b673 --- /dev/null +++ b/test/gh-1703.test.js @@ -0,0 +1,48 @@ + +/** + * Test dependencies. + */ + +var start = require('./common') + , assert = require('assert') + , mongoose = start.mongoose + , random = require('../lib/utils').random + , Query = require('../lib/query') + , Schema = mongoose.Schema + , SchemaType = mongoose.SchemaType + , CastError = mongoose.Error.CastError + , ValidatorError = mongoose.Error.ValidatorError + , ValidationError = mongoose.Error.ValidationError + , ObjectId = Schema.Types.ObjectId + , DocumentObjectId = mongoose.Types.ObjectId + , DocumentArray = mongoose.Types.DocumentArray + , EmbeddedDocument = mongoose.Types.Embedded + , MongooseArray = mongoose.Types.Array + , MongooseError = mongoose.Error; + +describe('(gh-1703) Dont pluralize collection names that dont end with a lowercase letter', function(){ + it('should not pluralize _temp_', function(done){ + var db = start(); + + var ASchema = new Schema ({ + value: { type: Schema.Types.Mixed } + }); + + var collectionName = '_temp_'; + var A = db.model(collectionName, ASchema); + assert.equal(A.collection.name, collectionName); + done(); + }); + it('should pluralize _temp', function(done){ + var db = start(); + + var ASchema = new Schema ({ + value: { type: Schema.Types.Mixed } + }); + + var collectionName = '_temp'; + var A = db.model(collectionName, ASchema); + assert.equal(A.collection.name, collectionName + 's'); + done(); + }) +});