Skip to content

Commit

Permalink
Don't pluralize model names not ending with letters
Browse files Browse the repository at this point in the history
closes #1703
  • Loading branch information
Refael Ackermann authored and aheckmann committed Sep 22, 2013
1 parent 5fdf815 commit 362fb1c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/utils.js
Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions 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();
})
});

0 comments on commit 362fb1c

Please sign in to comment.