diff --git a/changelog.md b/changelog.md
index b917dbd..cbf9cd4 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,6 @@
# Changelog
-v0.10.2 - 8ed75d2 - Dec 4th 2017
+v0.10.2 - Dec 4th 2017
* Fix for DataTypes not being exposed during `sequelize.import` calls
* *DEV* Added .editorconfig file to normalize editors and minimize whitespace changes
diff --git a/docs/api/model.md b/docs/api/model.md
index 421aaba..8d97cd5 100644
--- a/docs/api/model.md
+++ b/docs/api/model.md
@@ -80,7 +80,7 @@ UserMock.findOne().then(function (result) {
UserMock.$queueResult(UserMock.build(), { wasCreated: false });
UserMock.findOrCreate({
// ...
-}).spread(function (user, created) {
+}).then(function ([user, created]) {
// created == false
});
```
@@ -306,8 +306,8 @@ Name | Type | Description
-
-## findById(id) -> Promise.<Instance>
+
+## findBfindByPkyId(id) -> Promise.<Instance>
Executes a mock query to find an instance with the given ID value. Without any other
configuration, the default behavior when no queueud query result is present is to
diff --git a/docs/api/sequelize.md b/docs/api/sequelize.md
index 9f934c4..b6a4eae 100644
--- a/docs/api/sequelize.md
+++ b/docs/api/sequelize.md
@@ -71,7 +71,7 @@ Reference to the Util functions
## Promise
-Reference to the bluebird promise library
+Reference to the Promise library
diff --git a/docs/docs/mock-queries.md b/docs/docs/mock-queries.md
index f6aa926..4878fe1 100644
--- a/docs/docs/mock-queries.md
+++ b/docs/docs/mock-queries.md
@@ -98,7 +98,7 @@ User.$useHandler(function(query, queryOptions, done) {
if (query === "findOne") return User.build({id: 1});
});
User.$useHandler(function(query, queryOptions, done) {
- if (query === "findById") return User.build({id: queryOptions[0]});
+ if (query === "findByPk") return User.build({id: queryOptions[0]});
});
User.$useHandler(function(query, queryOptions, done) {
if (query === "findOrCreate") return User.build({id:1000});
@@ -107,7 +107,7 @@ User.$useHandler(function(query, queryOptions, done) {
User.findOne().then(function (user) {
user.get('id'); // === 1
});
-User.findById(123).then(function (user) {
+User.findByPk(123).then(function (user) {
user.get('id'); // === 123
});
User.findOrCreate().then(function (user) {
@@ -158,7 +158,7 @@ Some functions require additional parameters or configuration. You can specify b
```javascript
User.$queueResult( User.build(), { wasCreated: true } );
-User.findOrCreate().spread(function (user, wasCreated) {
+User.findOrCreate().then(function ([user, wasCreated]) {
wasCreated; // === true
});
```
diff --git a/package.json b/package.json
index a2974c8..7369cb3 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,6 @@
},
"homepage": "https://github.com/BlinkUX/sequelize-mock#readme",
"dependencies": {
- "bluebird": "^3.4.6",
"inflection": "^1.10.0",
"lodash": "^4.16.4"
},
diff --git a/src/instance.js b/src/instance.js
index a2cb256..823e15d 100644
--- a/src/instance.js
+++ b/src/instance.js
@@ -24,8 +24,7 @@
* @fileOverview Instances of Models created by Model function calls.
*/
-var bluebird = require('bluebird'),
- _ = require('lodash'),
+var _ = require('lodash'),
Errors = require('./errors');
var id = 0;
@@ -205,24 +204,6 @@ fakeModelInstance.prototype.get = function (key) {
}
};
-/**
- * Get plain value
- * @param {String} key Key yo get the value for
- * @return {Any}
- */
-fakeModelInstance.prototype.getDataValue = function (key) {
- return this._values[key];
-};
-
-/**
- * Set plain value
- * @param {String} key Key yo get the value for
- * @param {Any} value
- */
-fakeModelInstance.prototype.setDataValue = function (key, value) {
- this._values[key] = value;
-};
-
/**
* Triggers validation. If there are errors added through `$addValidationError` they will
* be returned and the queue of validation errors will be cleared.
@@ -250,7 +231,7 @@ fakeModelInstance.prototype.validate = function () {
this.$clearValidationErrors();
}
- return bluebird.resolve(validationError);
+ return Promise.resolve(validationError);
};
/**
@@ -279,7 +260,7 @@ fakeModelInstance.prototype.save = function () {
**/
fakeModelInstance.prototype.destroy = function () {
this._values.deletedAt = new Date();
- return bluebird.resolve();
+ return Promise.resolve();
};
/**
@@ -289,7 +270,7 @@ fakeModelInstance.prototype.destroy = function () {
* @return {Promise} will always resolve with the current instance
**/
fakeModelInstance.prototype.reload = function () {
- return bluebird.resolve(this);
+ return Promise.resolve(this);
};
/**
diff --git a/src/model.js b/src/model.js
index 313f447..e7c099a 100644
--- a/src/model.js
+++ b/src/model.js
@@ -10,8 +10,7 @@
* @fileOverview The base mock Model object for use in tests
*/
-var Promise = require('bluebird'),
- _ = require('lodash'),
+var _ = require('lodash'),
nodeutil = require('util'),
Utils = require('./utils'),
Instance = require('./instance'),
@@ -127,7 +126,7 @@ function fakeModel (name, defaults, opts) {
* UserMock.$queueResult(UserMock.build(), { wasCreated: false });
* UserMock.findOrCreate({
* // ...
- * }).spread(function (user, created) {
+ * }).then(function ([user, created]) {
* // created == false
* });
*
@@ -239,14 +238,6 @@ fakeModel.prototype.scope = function () {
return this;
};
-/**
- * No-op that returns a void.
- *
- * @instance
- * @return {undefined}
- **/
-fakeModel.prototype.addScope = function () {};
-
/**
* Executes a mock query to find all of the instances with any provided options. Without
* any other configuration, the default behavior when no queueud query result is present
@@ -346,11 +337,11 @@ fakeModel.prototype.findAndCountAll = function (options) {
* @param {Integer} id ID of the instance
* @return {Promise} Promise that resolves with an instance with the given ID
**/
-fakeModel.prototype.findById = function (id) {
+fakeModel.prototype.findByPk = function (id) {
var self = this;
return this.$query({
- query: "findById",
+ query: "findByPk",
queryOptions: arguments,
fallbackFn: !this.options.autoQueryFallback ? null : function () {
return Promise.resolve( self.build({ id: id }) );
@@ -395,6 +386,53 @@ fakeModel.prototype.findOne = function (obj) {
});
};
+
+/**
+ * Executes a mock query to count all of the instances with any provided options.
+ * Without any other configuration, the default behavior when no queueud query result
+ * is present is to create result with the value 1 wrapped in promise.
+ *
+ * To turn off this behavior, the `$autoQueryFallback` option on the model should be set
+ * to `false`.
+ *
+ * @example
+ * // This is an example of the default behavior with no queued results
+ * // If there is a queued result or failure, that will be returned instead
+ * User.count({
+ * where: {
+ * email: 'myEmail@example.com',
+ * },
+ * }).then(function (count) {
+ * // count returns the actual value
+ * count == 1; // true
+ * });
+ *
+ * @instance
+ * @method count
+ * @param {Object} [options] Options for the count query
+ * @param {Object} [options.where] Values that any automatically created Instances should have
+ * @return {Promise