Skip to content

Commit

Permalink
Merge 87a065f into 82ba824
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Aug 3, 2015
2 parents 82ba824 + 87a065f commit 2ee78fb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
28 changes: 13 additions & 15 deletions es5/lib/model.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Component Dependencies */
//
"use strict";

Object.defineProperty(exports, "__esModule", {
Expand All @@ -12,12 +14,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/* Component Dependencies */
//

var _blunder = require("blunder");
var _flowsync = require("flowsync");

var _blunder2 = _interopRequireDefault(_blunder);
var _flowsync2 = _interopRequireDefault(_flowsync);

var _fleming = require("fleming");

Expand All @@ -39,8 +38,6 @@ var _collectionJs2 = _interopRequireDefault(_collectionJs);

var _modelFinderJs2 = _interopRequireDefault(_modelFinderJs);

var flowsync = require("flowsync");

/* Private Method Symbols */
var callDeep = Symbol(),
addAssociation = Symbol(),
Expand Down Expand Up @@ -306,10 +303,10 @@ var Model = (function () {
done(null, cleanedMessages);
};

flowsync.mapParallel(attributeValidations, performValidation, compileValidatorResponses);
_flowsync2["default"].mapParallel(attributeValidations, performValidation, compileValidatorResponses);
};

flowsync.mapParallel(attributeNamesWithValidators, performValidationsForAttribute, compileInvalidAttributeList);
_flowsync2["default"].mapParallel(attributeNamesWithValidators, performValidationsForAttribute, compileInvalidAttributeList);
}
}, {
key: "include",
Expand Down Expand Up @@ -604,7 +601,7 @@ var Model = (function () {
}
});

flowsync.parallel(fetchTasks, function () {
_flowsync2["default"].parallel(fetchTasks, function () {
if (callback) {
callback(error, _this3);
}
Expand All @@ -629,7 +626,7 @@ var Model = (function () {
}

if (this[this.primaryKey]) {
flowsync.series([function (next) {
_flowsync2["default"].series([function (next) {
_this5[callDeep]("delete", function (associationDetails) {
return associationDetails.type !== "belongsTo" && associationDetails.dependent === true;
}, next);
Expand Down Expand Up @@ -665,7 +662,7 @@ var Model = (function () {
throw new Error("Cannot save without Model.database set.");
}

flowsync.series([function (next) {
_flowsync2["default"].series([function (next) {
_this6.beforeValidation(next);
}, function (next) {
_this6.isValid(function (valid) {
Expand All @@ -677,13 +674,14 @@ var Model = (function () {

if (hasInvalidAttributes) {
var errorPrefix = _this6.constructor.name + " is invalid";
var multiError = new _blunder2["default"]([], errorPrefix);
var multiError = [];
for (var invalidAttributeName in invalidAttributeList) {
var invalidAttributeMessages = invalidAttributeList[invalidAttributeName];

for (var index in invalidAttributeMessages) {
var invalidAttributeMessage = invalidAttributeMessages[index];
var error = new Error(invalidAttributeName + " " + invalidAttributeMessage);
error.name = errorPrefix;
multiError.push(error);
}
}
Expand Down Expand Up @@ -845,7 +843,7 @@ var Model = (function () {

var associationNames = Object.keys(this.associations);

flowsync.mapParallel(associationNames, function (associationName, next) {
_flowsync2["default"].mapParallel(associationNames, function (associationName, next) {

var associationDetails = _this8.associations[associationName];

Expand All @@ -871,7 +869,7 @@ var Model = (function () {
//collection set, and not many to many (nothing in that case)
if (collection) {
//let array = [].slice.call(collection);
flowsync.eachParallel(collection, function (collectionModel, finishSubStep) {
_flowsync2["default"].eachParallel(collection, function (collectionModel, finishSubStep) {
var result = predicate(associationDetails);
if (result) {
collectionModel[methodName](finishSubStep);
Expand Down
16 changes: 8 additions & 8 deletions es5/spec/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,15 +1144,15 @@ describe("Model(attributes, options)", function () {
});

it("should retun just one multi error object the appropiate number of errors", function (done) {
user.save(function (error) {
error.errors.length.should.equal(1);
user.save(function (errors) {
errors.length.should.equal(1);
done();
});
});

it("should retun just one multi error object the appropiate name", function (done) {
user.save(function (error) {
error.name.should.equal("User is invalid");
user.save(function (errors) {
errors[0].name.should.equal("User is invalid");
done();
});
});
Expand Down Expand Up @@ -2217,14 +2217,14 @@ describe("Model(attributes, options)", function () {
});

it("should call back with an error", function () {
user.save(function (error) {
error.should.be.instanceOf(Error);
user.save(function (errors) {
errors[0].should.be.instanceOf(Error);
});
});

it("should inform the user that the model is invalid", function () {
user.save(function (error) {
error.message.should.eql("photos must be present on User");
user.save(function (errors) {
errors[0].message.should.eql("photos must be present on User");
});
});
});
Expand Down
7 changes: 3 additions & 4 deletions es6/lib/model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const flowsync = require("flowsync");

/* Component Dependencies */
//
import MultiError from "blunder";
import flowsync from "flowsync";
import Datetime from "fleming";
import inflect from "jargon";
import Quirk from "quirk";
Expand Down Expand Up @@ -621,13 +619,14 @@ export default class Model {

if (hasInvalidAttributes) {
const errorPrefix = this.constructor.name + " is invalid";
const multiError = new MultiError([], errorPrefix);
const multiError = [];
for(let invalidAttributeName in invalidAttributeList) {
const invalidAttributeMessages = invalidAttributeList[invalidAttributeName];

for(let index in invalidAttributeMessages) {
const invalidAttributeMessage = invalidAttributeMessages[index];
const error = new Error(`${invalidAttributeName} ${invalidAttributeMessage}`);
error.name = errorPrefix;
multiError.push(error);
}
}
Expand Down
16 changes: 8 additions & 8 deletions es6/spec/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,15 @@ describe("Model(attributes, options)", () => {
});

it("should retun just one multi error object the appropiate number of errors", done => {
user.save((error) => {
error.errors.length.should.equal(1);
user.save((errors) => {
errors.length.should.equal(1);
done();
});
});

it("should retun just one multi error object the appropiate name", done => {
user.save((error) => {
error.name.should.equal("User is invalid");
user.save((errors) => {
errors[0].name.should.equal("User is invalid");
done();
});
});
Expand Down Expand Up @@ -2060,14 +2060,14 @@ describe("Model(attributes, options)", () => {
});

it("should call back with an error", () => {
user.save((error) => {
error.should.be.instanceOf(Error);
user.save((errors) => {
errors[0].should.be.instanceOf(Error);
});
});

it("should inform the user that the model is invalid", () => {
user.save((error) => {
error.message.should.eql("photos must be present on User");
user.save((errors) => {
errors[0].message.should.eql("photos must be present on User");
});
});
});
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dovima",
"version": "0.1.7",
"version": "0.1.8",
"description": "ES6 generic model with lots of useful special features.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -35,7 +35,6 @@
"homepage": "https://github.com/FreeAllMedia/dovima",
"dependencies": {
"almaden": "^0.1.0",
"blunder": "^0.1.0",
"fleming": "^0.1.0",
"flowsync": "^0.1.4",
"jargon": "^0.1.14",
Expand Down

0 comments on commit 2ee78fb

Please sign in to comment.