Skip to content

Commit 362fb1c

Browse files
Refael Ackermannaheckmann
Refael Ackermann
authored andcommitted
Don't pluralize model names not ending with letters
closes Automattic#1703
1 parent 5fdf815 commit 362fb1c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ exports.pluralization = [
5454
[/([m|l])ouse$/gi, '$1ice'],
5555
[/(quiz)$/gi, '$1zes'],
5656
[/s$/gi, 's'],
57+
[/([^a-z])$/, '$1'],
5758
[/$/gi, 's']
5859
];
5960
var rules = exports.pluralization;

test/gh-1703.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
/**
3+
* Test dependencies.
4+
*/
5+
6+
var start = require('./common')
7+
, assert = require('assert')
8+
, mongoose = start.mongoose
9+
, random = require('../lib/utils').random
10+
, Query = require('../lib/query')
11+
, Schema = mongoose.Schema
12+
, SchemaType = mongoose.SchemaType
13+
, CastError = mongoose.Error.CastError
14+
, ValidatorError = mongoose.Error.ValidatorError
15+
, ValidationError = mongoose.Error.ValidationError
16+
, ObjectId = Schema.Types.ObjectId
17+
, DocumentObjectId = mongoose.Types.ObjectId
18+
, DocumentArray = mongoose.Types.DocumentArray
19+
, EmbeddedDocument = mongoose.Types.Embedded
20+
, MongooseArray = mongoose.Types.Array
21+
, MongooseError = mongoose.Error;
22+
23+
describe('(gh-1703) Dont pluralize collection names that dont end with a lowercase letter', function(){
24+
it('should not pluralize _temp_', function(done){
25+
var db = start();
26+
27+
var ASchema = new Schema ({
28+
value: { type: Schema.Types.Mixed }
29+
});
30+
31+
var collectionName = '_temp_';
32+
var A = db.model(collectionName, ASchema);
33+
assert.equal(A.collection.name, collectionName);
34+
done();
35+
});
36+
it('should pluralize _temp', function(done){
37+
var db = start();
38+
39+
var ASchema = new Schema ({
40+
value: { type: Schema.Types.Mixed }
41+
});
42+
43+
var collectionName = '_temp';
44+
var A = db.model(collectionName, ASchema);
45+
assert.equal(A.collection.name, collectionName + 's');
46+
done();
47+
})
48+
});

0 commit comments

Comments
 (0)