Skip to content

Commit

Permalink
Merge branch 'release/0.1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrockwell committed Aug 18, 2015
2 parents 572b869 + f654ec6 commit f9ef2ba
Show file tree
Hide file tree
Showing 18 changed files with 832 additions and 483 deletions.
9 changes: 3 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"jasmine": false,
"es6": true
},

"rules": {
"no-alert": 2,
"no-array-constructor": 2,
Expand All @@ -32,7 +31,7 @@
"no-duplicate-case": 2,
"no-else-return": 0,
"no-empty": 2,
"no-empty-class": 2,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-eq-null": 0,
"no-eval": 2,
Expand All @@ -42,7 +41,7 @@
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-extra-strict": 2,
"strict": 2,
"no-fallthrough": 2,
"no-floating-decimal": 0,
"no-func-assign": 2,
Expand Down Expand Up @@ -108,7 +107,6 @@
"no-var": 0,
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 2,
"no-wrap-func": 2,

"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
Expand All @@ -128,7 +126,6 @@
"func-style": [0, "declaration"],
"generator-star": 0,
"generator-star-spacing": 0,
"global-strict": [2, "never"],
"guard-for-in": 0,
"handle-callback-err": 0,
"indent": 0,
Expand Down Expand Up @@ -172,4 +169,4 @@
"wrap-regex": 0,
"yoda": [2, "never"]
}
}
}
16 changes: 11 additions & 5 deletions es5/lib/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var _symbols = require("./symbols");

var _symbols2 = _interopRequireDefault(_symbols);

// TODO: Remove superfluous underscores from private data. _._validations should be _.validations

/**
* @class Model
*/
Expand All @@ -54,6 +56,8 @@ var _addAssociationJs = require("./addAssociation.js");

var _addAssociationJs2 = _interopRequireDefault(_addAssociationJs);

// TODO: Simplify. There's no need for "name" and "handler" keys.

var _modelFinderJs = require("../modelFinder.js");

var _modelFinderJs2 = _interopRequireDefault(_modelFinderJs);
Expand Down Expand Up @@ -146,6 +150,8 @@ var Model = (function () {
this.initialize();
}

// TODO: Simplify this.

_createClass(Model, [{
key: "hasOne",
value: function hasOne(associationName, associationConstructor) {
Expand Down Expand Up @@ -390,7 +396,10 @@ var Model = (function () {
}, {
key: _symbols2["default"].properties,
value: function value() {
return Object.keys(this);
var cleanedProperties = Object.keys(this).filter(function (key) {
return key !== "database";
});
return cleanedProperties;
}
}, {
key: _symbols2["default"].validations,
Expand Down Expand Up @@ -533,7 +542,6 @@ var Model = (function () {
})();

exports["default"] = Model;

function joinClass(classObject, methods) {
//construct a object with the additional methods
var obj = {};
Expand All @@ -542,9 +550,7 @@ function joinClass(classObject, methods) {
});
//add the additional methods to the prototype
Object.assign(classObject.prototype, obj);
}

joinClass(Model, [{ name: "fetch", handler: _fetchJs2["default"] }, { name: "save", handler: _saveJs2["default"] }, { name: _symbols2["default"].addAssociation, handler: _addAssociationJs2["default"] }]);
}joinClass(Model, [{ name: "fetch", handler: _fetchJs2["default"] }, { name: "save", handler: _saveJs2["default"] }, { name: _symbols2["default"].addAssociation, handler: _addAssociationJs2["default"] }]);

Object.defineProperties(Model, {
"find": {
Expand Down
4 changes: 4 additions & 0 deletions es5/lib/model/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var _symbols = require("./symbols");

var _symbols2 = _interopRequireDefault(_symbols);

var _util = require("util");

var _util2 = _interopRequireDefault(_util);

//private methods
function propagate(callback) {
//disabling this rule because break is not necessary when return is present
Expand Down
11 changes: 11 additions & 0 deletions es5/spec/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

var _proven = require("proven");

var index = require("../../index.js");

describe("index.js", function () {
it("should have a shortcut to proven's isNotEmpty", function () {
index.isNotEmpty.should.eql(_proven.isNotEmpty);
});
});
13 changes: 11 additions & 2 deletions es5/spec/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,17 @@ describe("Model(attributes, options)", function () {
});

describe(".properties", function () {
var properties = undefined;

beforeEach(function () {
properties = ["address", "addressId", "postalCode", "postalCodeId", "photos", "primaryPhoto", "primaryPhotoId", "photoLikes", "likedPhotos", "comments", "deletedComments", "id", "name", "age", "hasChildren"];
});
it("should return the name of all attributes plus associations on the model", function () {
user.properties.should.eql(["address", "addressId", "postalCode", "postalCodeId", "photos", "primaryPhoto", "primaryPhotoId", "photoLikes", "likedPhotos", "comments", "deletedComments", "id", "name", "age", "hasChildren"]);
user.properties.should.eql(properties);
});
it("should not return 'database'", function () {
user.database = {};
user.properties.should.eql(properties);
});
});

Expand Down Expand Up @@ -155,7 +164,7 @@ describe("Model(attributes, options)", function () {
});
});

describe("(static properties)", function () {
describe("(Static Properties)", function () {
describe(".attributes", function () {
afterEach(function () {
delete _testClassesJs.User.attributes.specialAttribute; //so does not affect other tests
Expand Down
95 changes: 95 additions & 0 deletions es5/spec/model/afterSave.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"use strict";

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _sinon = require("sinon");

var _sinon2 = _interopRequireDefault(_sinon);

var _almaden = require("almaden");

var _almaden2 = _interopRequireDefault(_almaden);

var _ = require("../../../");

var _2 = _interopRequireDefault(_);

var _databaseConfigJson = require("../databaseConfig.json");

var _databaseConfigJson2 = _interopRequireDefault(_databaseConfigJson);

describe("Model(attributes, options)", function () {
var model = undefined,
attributes = undefined,
afterSaveSpy = undefined;

// Example Class

var User = (function (_Model) {
_inherits(User, _Model);

function User() {
_classCallCheck(this, User);

_get(Object.getPrototypeOf(User.prototype), "constructor", this).apply(this, arguments);
}

_createClass(User, [{
key: "afterSave",
value: function afterSave(callback) {
afterSaveSpy();
callback();
}
}]);

return User;
})(_2["default"]);

beforeEach(function () {
afterSaveSpy = _sinon2["default"].spy();

_2["default"].database = new _almaden2["default"](_databaseConfigJson2["default"]);
// Mock save query
_2["default"].database.mock(_defineProperty({}, /insert into `users` \(`created_at`, `name`\) values \('.*', 'Bob'\)/, [{ "created_at": Date.now, "name": "Bob" }]));

// Instantiate model
attributes = {
name: "Bob"
};

model = new User(attributes);
});

describe(".afterSave(done)", function () {
describe("(With Callback)", function () {
it("should be called after .save", function (done) {
// throw util.inspect(model.afterSave, true, 4);
model.save(function (error) {
if (error) {
throw error;
}
afterSaveSpy.called.should.be["true"];
done();
});
});

// TODO: Enhance with callback waiting
it("should make the .save callback wait for the .afterSave callback");
});

// TODO: Enhance with synchronous hook
describe("(Without Callback)", function () {
it("should be called after .save is complete");
});
});
});
94 changes: 94 additions & 0 deletions es5/spec/model/beforeSave.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"use strict";

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _sinon = require("sinon");

var _sinon2 = _interopRequireDefault(_sinon);

var _almaden = require("almaden");

var _almaden2 = _interopRequireDefault(_almaden);

var _ = require("../../../");

var _2 = _interopRequireDefault(_);

var _databaseConfigJson = require("../databaseConfig.json");

var _databaseConfigJson2 = _interopRequireDefault(_databaseConfigJson);

describe("Model(attributes, options)", function () {
var model = undefined,
attributes = undefined,
options = undefined,
beforeSaveSpy = undefined;

var User = (function (_Model) {
_inherits(User, _Model);

function User() {
_classCallCheck(this, User);

_get(Object.getPrototypeOf(User.prototype), "constructor", this).apply(this, arguments);
}

_createClass(User, [{
key: "beforeSave",
value: function beforeSave(callback) {
beforeSaveSpy();
callback();
}
}]);

return User;
})(_2["default"]);

beforeEach(function () {
beforeSaveSpy = _sinon2["default"].spy();

_2["default"].database = new _almaden2["default"](_databaseConfigJson2["default"]);

// Mock save query
_2["default"].database.mock(_defineProperty({}, /insert into `users` \(`created_at`, `name`\) values \('.*', 'Bob'\)/, [{ "created_at": Date.now, "name": "Bob" }]));

attributes = {
"name": "Bob"
};

model = new User(attributes);
});

describe(".beforeSave(done)", function () {
describe("(With Callback)", function () {
it("should be called before .save", function (done) {
// throw util.inspect(model.afterSave, true, 4);
model.save(function (error) {
if (error) {
throw error;
}
beforeSaveSpy.called.should.be["true"];
done();
});
});

// TODO: Enhance with callback waiting
it("should make .save wait for .beforeSave callback");
});

// TODO: Enhance with synchronous hook
describe("(Without Callback)", function () {
it("should be called before .save");
});
});
});
1 change: 1 addition & 0 deletions es5/spec/model/database.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
Loading

0 comments on commit f9ef2ba

Please sign in to comment.