Skip to content

Commit

Permalink
Merge branch 'feature/scudl_refresh' into feature/fragmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Oct 20, 2015
2 parents ce3b484 + 691c1a0 commit ac8db92
Show file tree
Hide file tree
Showing 39 changed files with 1,766 additions and 688 deletions.
82 changes: 75 additions & 7 deletions es5/lib/app.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ module.exports = yeoman.generators.Base.extend({
name: "name",
message: "What is the model name? (use camel case please)",
"default": "myModel"
}, {
type: "input",
name: "attributeString",
message: "Provide the model attributes sepparated by a comma? (like name,link,email,contactPhone)",
"default": "name"
}];

this.prompt(prompts, (function (props) {
this.props = props;

done();
}).bind(this));
},
Expand All @@ -42,20 +46,84 @@ module.exports = yeoman.generators.Base.extend({
name: this.props.name,
Name: (0, _jargon2["default"])(this.props.name).pascal.toString(),
names: (0, _jargon2["default"])(this.props.name).plural.toString(),
_name: (0, _jargon2["default"])(this.props.name).snake.toString()
_name: (0, _jargon2["default"])(this.props.name).snake.toString(),
attributes: this.props.attributes,
attributeString: this.props.attributeString
};

context.attributes = context.attributeString.split(",");

//filling a strings that are going to be used in the templates to mock a test entity
context.attributesWithValues = "";
context.fieldsWithValues = "";
context.validateString = "";
context.attributes.forEach(function (attributeName, index) {
if (index > 0) {
var breakLine = ",\n";
context.attributesWithValues += breakLine;
context.fieldsWithValues += breakLine;
context.validateString += breakLine;
}
var snakeAttributeName = (0, _jargon2["default"])(attributeName).snake.toString();
context.attributesWithValues += "\"" + attributeName + "\": \"test " + attributeName + "\"";
context.fieldsWithValues += "\"" + snakeAttributeName + "\": " + context.name + "." + attributeName;
context.validateString += "this.ensure(\"" + attributeName + "\", isNotEmpty);";
});
context.attributesJson = JSON.stringify(context.attributesWithValues);

//copy feature steps
["_model.common.steps.js", "_model.show.steps.js", "_model.create.steps.js", "_model.update.steps.js", "_model.delete.steps.js", "_model.list.steps.js"].forEach(function (templatePath) {
["_model.show.steps.js", "_model.create.steps.js", "_model.update.steps.js", "_model.delete.steps.js", "_model.list.steps.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name);
_this.fs.copyTpl(_this.templatePath("es6/features/steps/" + templatePath), _this.destinationPath("es6/features/steps/" + context.name + "/" + newName), context);
}, this);

//copy fixtures
this.fs.copyTpl(this.templatePath("es6/spec/fixtures/_modelFixtures.json"), this.destinationPath("es6/spec/fixtures/" + context.names + ".json"), context);
//copy common steps
["_common.steps.js", "_accessToken.steps.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/" + templatePath), _this.destinationPath("es6/features/steps/" + newName), context);
}, this);

//copy common functions
["_jsonWebToken.js", "_language.js", "_request.js", "_values.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/common/" + templatePath), _this.destinationPath("es6/features/steps/common/" + newName), context);
}, this);

//copy support files
["_hooks.js", "_world.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/support/" + templatePath), _this.destinationPath("es6/features/support/" + newName), context);
}, this);

//copy controllers
["_modelController.js", "_applicationController.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/controllers/" + templatePath), _this.destinationPath("es6/app/controllers/" + newName), context);
}, this);

//copy managers
["_accountManager.js", "_modelManager.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/managers/" + templatePath), _this.destinationPath("es6/app/managers/" + newName), context);
}, this);

//copy model
this.fs.copyTpl(this.templatePath("es6/app/models/_model.js"), this.destinationPath("es6/app/models/" + context.name + ".js"), context);

//copy controller
this.fs.copyTpl(this.templatePath("es6/app/controllers/_modelController.js"), this.destinationPath("es6/app/controllers/" + context.name + "Controller.js"), context);
//copy model spec
this.fs.copyTpl(this.templatePath("es6/spec/_model.spec.js"), this.destinationPath("es6/spec/" + context.name + ".spec.js"), context);

//copy routers
["_modelRouter.js", "_modelRoutes.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/routers/" + templatePath), _this.destinationPath("es6/app/routers/" + newName), context);
}, this);

//copy misc
["_errors.js", "_server.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/" + templatePath), _this.destinationPath("es6/app/" + newName), context);
}, this);
},

install: function yoInstall() {
Expand Down
8 changes: 7 additions & 1 deletion es5/lib/features.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ module.exports = yeoman.generators.Base.extend({
//copy features
["_model.show.feature", "_model.create.feature", "_model.update.feature", "_model.delete.feature", "_model.list.feature"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name);
_this.fs.copyTpl(_this.templatePath("es6/features/" + templatePath), _this.destinationPath("es6/features/" + context.name + "/" + newName), context);
_this.fs.copyTpl(_this.templatePath("es6/features/" + templatePath), _this.destinationPath("features/" + context.name + "/" + newName), context);
}, this);

//copy access token feature
["_accessToken.feature"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/" + templatePath), _this.destinationPath("features/" + newName), context);
}, this);
},

Expand Down
81 changes: 49 additions & 32 deletions es5/spec/app.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,53 @@ var helpers = require("yeoman-generator").test;
var os = require("os");

describe("troupe", function () {
var name = undefined;

before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/app")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name
}).on("end", done);
});

it("creates step files", function () {
assert.file(["es6/features/steps/" + name + "/" + name + ".common.steps.js", "es6/features/steps/" + name + "/" + name + ".show.steps.js", "es6/features/steps/" + name + "/" + name + ".create.steps.js", "es6/features/steps/" + name + "/" + name + ".update.steps.js", "es6/features/steps/" + name + "/" + name + ".delete.steps.js", "es6/features/steps/" + name + "/" + name + ".list.steps.js"]);
});

it("creates the fixture file", function () {
assert.file(["es6/spec/fixtures/" + name + "s.json"]);
});

it("creates the controller", function () {
assert.file(["es6/app/controllers/" + name + "Controller.js"]);
});

describe("(about the content of every feature)", function () {
it("should have some this.querySpy = on it", function () {
assert.fileContent([["es6/features/steps/" + name + "/" + name + ".show.steps.js", "this.querySpy ="]]);
});

describe("(controller content)", function () {
it("should have filters for validation", function () {
assert.fileContent([["es6/app/controllers/" + name + "Controller.js", "filters()"], ["es6/app/controllers/" + name + "Controller.js", "[validateId]"], ["es6/app/controllers/" + name + "Controller.js", "[validateData]"]]);
});
});
});
var name = undefined;

before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/app")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name,
attributes: "name"
}).on("end", done);
});

it("creates cucumber js files", function () {
assert.file(["es6/features/steps/" + name + "/" + name + ".show.steps.js", "es6/features/steps/" + name + "/" + name + ".create.steps.js", "es6/features/steps/" + name + "/" + name + ".update.steps.js", "es6/features/steps/" + name + "/" + name + ".delete.steps.js", "es6/features/steps/" + name + "/" + name + ".list.steps.js", "es6/features/steps/common/jsonWebToken.js", "es6/features/steps/common/language.js", "es6/features/steps/common/request.js", "es6/features/steps/common/values.js", "es6/features/steps/accessToken.steps.js", "es6/features/support/hooks.js", "es6/features/support/world.js"]);
});

it("creates a common step file", function () {
assert.file(["es6/features/steps/common.steps.js"]);
});

it("creates the model and his spec", function () {
assert.file(["es6/app/models/" + name + ".js", "es6/spec/" + name + ".spec.js"]);
});

it("creates the controllers", function () {
assert.file(["es6/app/controllers/" + name + "Controller.js", "es6/app/controllers/applicationController.js"]);
});

it("creates the managers", function () {
assert.file(["es6/app/managers/" + name + "Manager.js", "es6/app/managers/accountManager.js"]);
});

it("creates the router", function () {
assert.file(["es6/app/routers/" + name + "Router.js", "es6/app/routers/" + name + "Routes.js"]);
});

it("creates misc files", function () {
assert.file(["es6/app/errors.js", "es6/app/server.js"]);
});

describe("(about the content of every feature)", function () {
it("should have some this.database = on it", function () {
assert.fileContent([["es6/features/steps/" + name + "/" + name + ".show.steps.js", "this.database"]]);
});

describe("(controller content)", function () {
it("should have filters for validation", function () {
assert.fileContent([["es6/app/controllers/" + name + "Controller.js", "filters()"], ["es6/app/controllers/" + name + "Controller.js", "[pullAccountIdFromRequest]"]]);
});
});
});
});
20 changes: 10 additions & 10 deletions es5/spec/features.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var helpers = require("yeoman-generator").test;
var os = require("os");

describe("troupe:features", function () {
var name = undefined;
var name = undefined;

before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/features")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name
}).on("end", done);
});
before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/features")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name
}).on("end", done);
});

it("creates feature files", function () {
assert.file(["es6/features/" + name + "/" + name + ".show.feature", "es6/features/" + name + "/" + name + ".create.feature", "es6/features/" + name + "/" + name + ".update.feature", "es6/features/" + name + "/" + name + ".delete.feature", "es6/features/" + name + "/" + name + ".list.feature"]);
});
it("creates feature files", function () {
assert.file(["features/" + name + "/" + name + ".show.feature", "features/" + name + "/" + name + ".create.feature", "features/" + name + "/" + name + ".update.feature", "features/" + name + "/" + name + ".delete.feature", "features/" + name + "/" + name + ".list.feature", "features/accessToken.feature"]);
});
});
Loading

0 comments on commit ac8db92

Please sign in to comment.