Skip to content

Commit

Permalink
all tests pass for fixture plural names
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherif BOUCHELAGHEM committed Apr 19, 2016
1 parent 47134ea commit e526bd4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
8 changes: 6 additions & 2 deletions supermodel/index.js
Expand Up @@ -81,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 @@ -91,7 +96,6 @@ 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/' + _.pluralize(options.name));
done();
Expand Down
65 changes: 65 additions & 0 deletions test/supermodel.test.js
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 e526bd4

Please sign in to comment.