Skip to content

Commit

Permalink
fix: don't call overloaded versions of find functions internally (#13951
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sdepold committed Jan 22, 2022
1 parent 9e108e3 commit b253d8e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 10 deletions.
23 changes: 17 additions & 6 deletions dev/release-v6.ts
Expand Up @@ -35,16 +35,23 @@ const RELEASING_COLUMN_ID = 17444349;
process.exit(1);
}

const github = new Octokit({
auth: token
});
const github = new Octokit({ auth: token });
const commits = await getCommitsFromProject(github);

await Promise.all(commits.map(commit => mergeCommit(github, commit)));
await processCommitsInSeries(github, commits);
})();

// Helpers

async function processCommitsInSeries(github: Octokit, commits: CardCommit[]) {
let commit: CardCommit | undefined = commits.shift();

while (commit) {
await mergeCommit(github, commit);
commit = commits.shift();
}
}

async function getCommitsFromProject(github: Octokit): Promise<CardCommit[]> {
const cards = await github.rest.projects.listCards({
column_id: TO_BE_RELEASED_COLUMN_ID
Expand Down Expand Up @@ -110,15 +117,19 @@ function mergeCommitTeaser(commit: PullRequest) {
}

async function moveCard(github: Octokit, card: Card, to: number) {
let result = 'skipped';

if (process.env.DRY_RUN === 'false') {
const a = await github.rest.projects.moveCard({
const response = await github.rest.projects.moveCard({
card_id: card.id,
position: 'bottom',
column_id: to
});

console.log(a);
result = response.status === 201 ? 'success' : 'error';
}

console.info('- Card moved to column:', result);
}

async function gitMerge(sha: string) {
Expand Down
8 changes: 4 additions & 4 deletions lib/model.js
Expand Up @@ -1916,7 +1916,7 @@ class Model {
}

// Bypass a possible overloaded findOne
return await this.findOne(options);
return await Model.findOne.call(this, options);
}

/**
Expand Down Expand Up @@ -1950,9 +1950,9 @@ class Model {
}

// Bypass a possible overloaded findAll.
return await this.findAll(_.defaults(options, {
plain: true
}));
return await Model.findAll.call(this, (_.defaults(options, {
plain: true,
})));
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions test/unit/model/find-by-pk.test.js
@@ -0,0 +1,42 @@
'use strict';

const chai = require('chai');

const expect = chai.expect;
const Support = require('../support');

const Sequelize = Support.Sequelize;
const Op = Sequelize.Op;
const current = Support.sequelize;
const sinon = require('sinon');
const DataTypes = require('../../../lib/data-types');

describe(Support.getTestDialectTeaser('Model'), () => {
describe('method findByPk', () => {
beforeEach(function () {
this.stub = sinon.stub(Sequelize.Model, 'findAll').resolves();
});
afterEach(() => {
sinon.restore();
});

it('should call internal findOne() method if findOne() is overridden', async () => {
const Model = current.define('model', {
unique1: {
type: DataTypes.INTEGER,
unique: 'unique',
},
unique2: {
type: DataTypes.INTEGER,
unique: 'unique',
},
});
Model.findOne = sinon.stub();
sinon.spy(Sequelize.Model, 'findOne');

await Model.findByPk(1);
Model.findOne.should.not.have.been.called;
Sequelize.Model.findOne.should.have.been.called;
});
});
});
Expand Up @@ -105,5 +105,22 @@ describe(Support.getTestDialectTeaser('Model'), () => {
await Model.findOne({ where: { unique1: 42 } });
expect(this.stub.getCall(0).args[0]).to.be.an('object').to.have.property('limit');
});
it('should call internal findAll() method if findOne() is overridden', async () => {
const Model = current.define('model', {
unique1: {
type: DataTypes.INTEGER,
unique: 'unique',
},
unique2: {
type: DataTypes.INTEGER,
unique: 'unique',
},
});
Model.findAll = sinon.stub();

await Model.findOne();
Model.findAll.should.not.have.been.called;
Sequelize.Model.findAll.should.have.been.called;
});
});
});
File renamed without changes.
File renamed without changes.

0 comments on commit b253d8e

Please sign in to comment.