From fc3808031f77956f51ef675c808d3cd560407cfc Mon Sep 17 00:00:00 2001 From: Douglas Matoso Date: Sat, 29 Oct 2016 11:13:54 -0200 Subject: [PATCH] Add underscored: true option to generated model when created with --underscored flag --- lib/assets/models/model.js | 1 + lib/helpers/model-helper.js | 3 ++- test/model/create.test.js | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/assets/models/model.js b/lib/assets/models/model.js index ea710bb8..a9b4eee1 100644 --- a/lib/assets/models/model.js +++ b/lib/assets/models/model.js @@ -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 diff --git a/lib/helpers/model-helper.js b/lib/helpers/model-helper.js index bccd15f5..334db72c 100644 --- a/lib/helpers/model-helper.js +++ b/lib/helpers/model-helper.js @@ -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 }); }, diff --git a/test/model/create.test.js b/test/model/create.test.js index 319e0938..5f640b5f 100644 --- a/test/model/create.test.js +++ b/test/model/create.test.js @@ -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)); + }); + }); }); });