mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Replaced removed Bookshelf findWhere function
- as per https://github.com/bookshelf/bookshelf/wiki/Migrating-from-0.15.1-to-1.0.0#collectionfindwhere, the `findWhere` function was removed - `find` can be used in combination with `matchFunc` and then checking the values against each other to keep the same functionality - also updates the tests to reflect the change in number of function calls
This commit is contained in:
parent
23c207cefc
commit
2d639ad4a1
2 changed files with 12 additions and 10 deletions
|
@ -158,7 +158,12 @@ const addFixturesForRelation = function addFixturesForRelation(relationFixture,
|
|||
toItems = _.reject(toItems, function (item) {
|
||||
return fromItem
|
||||
.related(relationFixture.from.relation)
|
||||
.findWhere(matchObj(relationFixture.to.match, item));
|
||||
.find((model) => {
|
||||
const objectToMatch = matchObj(relationFixture.to.match, item);
|
||||
return Object.keys(objectToMatch).every(function (keyToCheck) {
|
||||
return model.get(keyToCheck) === objectToMatch[keyToCheck];
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (toItems && toItems.length > 0) {
|
||||
|
|
|
@ -143,7 +143,7 @@ describe('Migration Fixture Utils', function () {
|
|||
it('should call attach for permissions-roles', function (done) {
|
||||
const fromItem = {
|
||||
related: sinon.stub().returnsThis(),
|
||||
findWhere: sinon.stub().returns()
|
||||
find: sinon.stub().returns()
|
||||
};
|
||||
|
||||
const toItem = [{get: sinon.stub()}];
|
||||
|
@ -171,8 +171,7 @@ describe('Migration Fixture Utils', function () {
|
|||
baseUtilAttachStub.callCount.should.eql(80);
|
||||
|
||||
fromItem.related.callCount.should.eql(80);
|
||||
fromItem.findWhere.callCount.should.eql(80);
|
||||
toItem[0].get.callCount.should.eql(160);
|
||||
fromItem.find.callCount.should.eql(80);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
|
@ -181,7 +180,7 @@ describe('Migration Fixture Utils', function () {
|
|||
it('should call attach for posts-tags', function (done) {
|
||||
const fromItem = {
|
||||
related: sinon.stub().returnsThis(),
|
||||
findWhere: sinon.stub().returns()
|
||||
find: sinon.stub().returns()
|
||||
};
|
||||
|
||||
const toItem = [{get: sinon.stub()}];
|
||||
|
@ -207,8 +206,7 @@ describe('Migration Fixture Utils', function () {
|
|||
dataMethodStub.filter.callCount.should.eql(7);
|
||||
dataMethodStub.find.callCount.should.eql(7);
|
||||
fromItem.related.callCount.should.eql(7);
|
||||
fromItem.findWhere.callCount.should.eql(7);
|
||||
toItem[0].get.callCount.should.eql(7);
|
||||
fromItem.find.callCount.should.eql(7);
|
||||
baseUtilAttachStub.callCount.should.eql(7);
|
||||
|
||||
done();
|
||||
|
@ -218,7 +216,7 @@ describe('Migration Fixture Utils', function () {
|
|||
it('will not call attach for posts-tags if already present', function (done) {
|
||||
const fromItem = {
|
||||
related: sinon.stub().returnsThis(),
|
||||
findWhere: sinon.stub().returns({}),
|
||||
find: sinon.stub().returns({}),
|
||||
tags: sinon.stub().returnsThis(),
|
||||
attach: sinon.stub().returns(Promise.resolve({}))
|
||||
};
|
||||
|
@ -246,8 +244,7 @@ describe('Migration Fixture Utils', function () {
|
|||
dataMethodStub.find.callCount.should.eql(7);
|
||||
|
||||
fromItem.related.callCount.should.eql(7);
|
||||
fromItem.findWhere.callCount.should.eql(7);
|
||||
toItem[0].get.callCount.should.eql(7);
|
||||
fromItem.find.callCount.should.eql(7);
|
||||
|
||||
fromItem.tags.called.should.be.false();
|
||||
fromItem.attach.called.should.be.false();
|
||||
|
|
Loading…
Add table
Reference in a new issue