Skip to content

Commit

Permalink
Add underscored: true option to generated model when created with --u…
Browse files Browse the repository at this point in the history
…nderscored flag (#380)
  • Loading branch information
doug2k1 authored and sushantdhiman committed Oct 29, 2016
1 parent dd45cdc commit 6213516
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/assets/models/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function(sequelize, DataTypes) {
<%= (Object.keys(attributes).length - 1) > index ? ',' : '' %>
<% }) %>
}, {
<%= underscored ? 'underscored: true,' : '' %>
classMethods: {
associate: function(models) {
// associations can be defined here
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/model-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = {
generateFileContent: function (args) {
return helpers.template.render('models/model.js', {
name: args.name,
attributes: this.transformAttributes(args.attributes)
attributes: this.transformAttributes(args.attributes),
underscored: args.underscored
});
},

Expand Down
25 changes: 25 additions & 0 deletions test/model/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ var _ = require('lodash');
.pipe(helpers.teardown(done));
});
});

it('generates the model content correctly', function (done) {
var flags = {
name: 'User',
attributes: attributes
};

var targetContent = attrUnd.underscored ?
'underscored: true'
: '{\n classMethods';

if ( attrUnd.underscored ) {
flags.underscored = attrUnd.underscored;
}

prepare({
flags: flags
}, function () {
gulp
.src(Support.resolveSupportPath('tmp', 'models'))
.pipe(helpers.readFile('user.js'))
.pipe(helpers.ensureContent(targetContent))
.pipe(helpers.teardown(done));
});
});
});
});

Expand Down

0 comments on commit 6213516

Please sign in to comment.