Skip to content

Commit

Permalink
fix(gen): camelCase endpoint name when used in variable name
Browse files Browse the repository at this point in the history
Closes #540
  • Loading branch information
kingcody committed Sep 10, 2014
1 parent 3536b45 commit 7362080
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions endpoint/templates/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var proxyquire = require('proxyquire').noPreserveCache();

/* <%= name %>.controller stub */
var <%= name %>Ctrl = {
var <%= cameledName %>Ctrl = {
index: '<%= name %>Ctrl.index'<% if(filters.mongoose) { %>,
show: '<%= name %>Ctrl.show',
create: '<%= name %>Ctrl.create',
Expand All @@ -25,7 +25,7 @@ var <%= name %>Ctrl = {
return router;
}
},
'./<%= name %>.controller': <%= name %>Ctrl
'./<%= name %>.controller': <%= cameledName %>Ctrl
});

describe('<%= classedName %> API Router:', function() {
Expand Down
30 changes: 15 additions & 15 deletions endpoint/templates/name.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ var <%= classedName %> = require('./<%= name %>.model');<% } %>
// Get list of <%= name %>s
exports.index = function(req, res) {<% if (!filters.mongoose) { %>
res.json([]);<% } %><% if (filters.mongoose) { %>
<%= classedName %>.find(function (err, <%= name %>s) {
<%= classedName %>.find(function (err, <%= cameledName %>s) {
if(err) { return handleError(res, err); }
return res.json(200, <%= name %>s);
return res.json(200, <%= cameledName %>s);
});<% } %>
};<% if (filters.mongoose) { %>
// Get a single <%= name %>
exports.show = function(req, res) {
<%= classedName %>.findById(req.params.id, function (err, <%= name %>) {
<%= classedName %>.findById(req.params.id, function (err, <%= cameledName %>) {
if(err) { return handleError(res, err); }
if(!<%= name %>) { return res.send(404); }
return res.json(<%= name %>);
if(!<%= cameledName %>) { return res.send(404); }
return res.json(<%= cameledName %>);
});
};

// Creates a new <%= name %> in the DB.
exports.create = function(req, res) {
<%= classedName %>.create(req.body, function(err, <%= name %>) {
<%= classedName %>.create(req.body, function(err, <%= cameledName %>) {
if(err) { return handleError(res, err); }
return res.json(201, <%= name %>);
return res.json(201, <%= cameledName %>);
});
};

// Updates an existing <%= name %> in the DB.
exports.update = function(req, res) {
if(req.body._id) { delete req.body._id; }
<%= classedName %>.findById(req.params.id, function (err, <%= name %>) {
<%= classedName %>.findById(req.params.id, function (err, <%= cameledName %>) {
if (err) { return handleError(res, err); }
if(!<%= name %>) { return res.send(404); }
var updated = _.merge(<%= name %>, req.body);
if(!<%= cameledName %>) { return res.send(404); }
var updated = _.merge(<%= cameledName %>, req.body);
updated.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, <%= name %>);
return res.json(200, <%= cameledName %>);
});
});
};

// Deletes a <%= name %> from the DB.
exports.destroy = function(req, res) {
<%= classedName %>.findById(req.params.id, function (err, <%= name %>) {
<%= classedName %>.findById(req.params.id, function (err, <%= cameledName %>) {
if(err) { return handleError(res, err); }
if(!<%= name %>) { return res.send(404); }
<%= name %>.remove(function(err) {
if(!<%= cameledName %>) { return res.send(404); }
<%= cameledName %>.remove(function(err) {
if(err) { return handleError(res, err); }
return res.send(204);
});
Expand All @@ -57,4 +57,4 @@ exports.destroy = function(req, res) {

function handleError(res, err) {
return res.send(500, err);
}<% } %>
}<% } %>
16 changes: 8 additions & 8 deletions endpoint/templates/name.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var new<%= classedName %>;<% } %>
describe('<%= classedName %> API:', function() {

describe('GET <%= route %>', function() {
var <%= name %>s;
var <%= cameledName %>s;

beforeEach(function(done) {
request(app)
Expand All @@ -17,13 +17,13 @@ describe('<%= classedName %> API:', function() {
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
<%= name %>s = res.body;
<%= cameledName %>s = res.body;
done();
});
});

it('should respond with JSON array', function() {
<%= name %>s.should.be.instanceOf(Array);
<%= cameledName %>s.should.be.instanceOf(Array);
});

});<% if(filters.mongoose) { %>
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('<%= classedName %> API:', function() {
});

describe('GET <%= route %>/:id', function() {
var <%= name %>;
var <%= cameledName %>;

beforeEach(function(done) {
request(app)
Expand All @@ -62,18 +62,18 @@ describe('<%= classedName %> API:', function() {
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
<%= name %> = res.body;
<%= cameledName %> = res.body;
done();
});
});

afterEach(function() {
<%= name %> = {};
<%= cameledName %> = {};
});

it('should respond with the requested <%= name %>', function() {
<%= name %>.name.should.equal('New <%= classedName %>');
<%= name %>.info.should.equal('This is the brand new <%= name %>!!!');
<%= cameledName %>.name.should.equal('New <%= classedName %>');
<%= cameledName %>.info.should.equal('This is the brand new <%= name %>!!!');
});

});
Expand Down

0 comments on commit 7362080

Please sign in to comment.