Skip to content

Commit

Permalink
Merge pull request #119 from donejs/fix-509-generate-plural-fixture-n…
Browse files Browse the repository at this point in the history
…ames

Fix 509 generate plural fixture names
  • Loading branch information
matthewp committed Jun 4, 2016
2 parents 8589bfb + e526bd4 commit c6cc995
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
],
"dependencies": {
"lodash": "^3.10.0",
"lodash-inflection": "^1.3.2",
"lodash.upperfirst": "^4.1.2",
"q": "^1.4.1",
"semver": "^5.1.0",
Expand Down
12 changes: 9 additions & 3 deletions supermodel/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var generators = require('yeoman-generator');
var path = require('path');
var _ = require('lodash');

var utils = require('../lib/utils');
var upperFirst = require("lodash.upperfirst");
var utils = require('../lib/utils');
Expand Down Expand Up @@ -58,6 +59,7 @@ module.exports = generators.Base.extend({
writing: function () {
var self = this;
var done = this.async();
_.mixin(require("lodash-inflection"));

var pkg = utils.getPkgOrBail(this, done);
if(!pkg) {
Expand All @@ -79,7 +81,12 @@ module.exports = generators.Base.extend({
}

this.modelFiles.forEach(function(name) {
var target = name.replace('model', options.name);
var target;
if (name == 'fixtures/model.js') {
target = name.replace('model', _.pluralize(options.name));
} else {
target = name.replace('model', options.name);
}
self.fs.copyTpl(
self.templatePath(name),
self.destinationPath(path.join(folder, 'models', target)),
Expand All @@ -89,9 +96,8 @@ module.exports = generators.Base.extend({

var modelTest = this.destinationPath(path.join(folder, 'models', 'test.js'));
utils.addImport(modelTest, appName + '/models/' + options.name + '_test');

var fixturesFile = this.destinationPath(path.join(folder, 'models', 'fixtures', 'fixtures.js'));
utils.addImport(fixturesFile, appName + '/models/fixtures/' + options.name);
utils.addImport(fixturesFile, appName + '/models/fixtures/' + _.pluralize(options.name));
done();
}
});
65 changes: 65 additions & 0 deletions test/supermodel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,70 @@ describe('generator-donejs', function () {
});

});

describe('Fixtures should be in plural names',function(){
it('makes regular plural names', function (done) {
var tmpDir;
helpers.run(path.join(__dirname, '../supermodel'))
.inTmpDir(function (dir) {
tmpDir = dir;
fs.copySync(path.join( __dirname, "tests", "basics" ), dir)
})
.withOptions({
skipInstall: true
})
.withPrompts({
name: 'message',
url: ' /messages',
idProp: "id"
})
.on('end', function () {
assert( fs.existsSync( path.join(tmpDir, "src","models", "fixtures", "messages.js")), "messages.js exists" );
done();
});
});

it('makes irregular plural names', function (done) {
var tmpDir;
helpers.run(path.join(__dirname, '../supermodel'))
.inTmpDir(function (dir) {
tmpDir = dir;
fs.copySync(path.join( __dirname, "tests", "basics" ), dir)
})
.withOptions({
skipInstall: true
})
.withPrompts({
name: 'person',
url: ' /people',
idProp: "id"
})
.on('end', function () {
assert( fs.existsSync(path.join(tmpDir, "src","models", "fixtures", "people.js")), "people.js exists" );
done();
});
});

it('makes uncountable plural names', function (done) {
var tmpDir;
helpers.run(path.join(__dirname, '../supermodel'))
.inTmpDir(function (dir) {
tmpDir = dir;
fs.copySync(path.join( __dirname, "tests", "basics" ), dir)
})
.withOptions({
skipInstall: true
})
.withPrompts({
name: 'equipment',
url: ' /equipment',
idProp: "id"
})
.on('end', function () {
assert( fs.existsSync( path.join( tmpDir, "src", "models", "fixtures", "equipment.js" ) ), "equipment.js exists" );
done();
});
});
});
});
});

0 comments on commit c6cc995

Please sign in to comment.