Skip to content

Commit

Permalink
add option to turn model name to lower case. closes #15
Browse files Browse the repository at this point in the history
version 0.2.5
  • Loading branch information
florianholzapfel committed Aug 16, 2013
1 parent 3158adb commit 4a602a3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ serve(app, model, [options])
* version - An API version that will be prefixed to the rest path. Defaults to ```v1```
* middleware - An express middleware or an array of express middlewares that will be used.
* plural - If ```true```, does not pluralize the database model name. Default is ```false```
* lowercase - If ```true```, turn model name to lower case before generating the routes.
* exclude - String of comma separated field names which are not to be returned by queries.
* postProcess - A middleware to be called after the response has been sent.
It is only executed on success. If an error is sent to the client,
Expand Down
8 changes: 5 additions & 3 deletions lib/express-restify-mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ var restify = function (app, model, options) {
app.delete = app.del;

var apiUri = options.plural === true ? '%s%s/%ss' : '%s%s/%s';
var modelName = options.lowercase === true ? model.modelName.toLowerCase()
: model.modelName;

var uri_items = util.format(apiUri, options.prefix, options.version,
model.modelName);
modelName);
var uri_item = util.format(apiUri + '/:id', options.prefix, options.version,
model.modelName);
modelName);
var uri_count = util.format(apiUri + '/count', options.prefix,
options.version, model.modelName);
options.version, modelName);

function buildQuery(query, options) {
var excludedarr = exclude ? exclude.split(',') : [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "express-restify-mongoose",
"description": "Easily restify mongoose database",
"version": "0.2.4",
"version": "0.2.5",
"author": {
"name": "Florian Holzapfel",
"email": "flo.holzapfel@gmail.com"
Expand Down
45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,51 @@ function Restify() {
}
});

describe('Lower case model name', function () {
var savedCustomer, server,
app = createFn();

// only restify's routes are case sensitive
if (app.isRestify) {
setup();

before(function (done) {
erm.serve(app, setup.customerModel, {
lowercase: true,
restify: app.isRestify
});
server = app.listen(testPort, done);
});

after(function (done) {
if (app.close) {
return app.close(done);
}
server.close(done);
});

it('200 GET customers', function (done) {
request.get({
url: util.format('%s/api/v1/customers', testUrl),
json: true
}, function (err, res, body) {
assert.equal(res.statusCode, 200, 'Wrong status code');
done();
});
});

it('404 GET Customers', function (done) {
request.get({
url: util.format('%s/api/v1/Customers', testUrl),
json: true
}, function (err, res, body) {
assert.equal(res.statusCode, 404, 'Wrong status code');
done();
});
});
}
});

describe('postProcess', function () {
var savedCustomer, server, postProcess,
app = createFn();
Expand Down

0 comments on commit 4a602a3

Please sign in to comment.