mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Fixed transaction logic in data importer
https://github.com/TryGhost/Toolbox/issues/130 The transaction no longer commits in the promise chain, which wasn't valid logic for a transaction, since it is commited automatically when the promise chain resolves, and rollsback automatically when the promise chain rejects. This makes code which fails during the transaction error in the right place, instead of getting stuck here. (Especially good for writing tests). The tests for this code can now live in the integration folder.
This commit is contained in:
parent
f1798119d3
commit
a5484a0fe1
@ -112,7 +112,7 @@ DataImporter = {
|
||||
});
|
||||
});
|
||||
|
||||
sequence(ops)
|
||||
return sequence(ops)
|
||||
.then(function () {
|
||||
results.forEach(function (promise) {
|
||||
if (!promise.isFulfilled()) {
|
||||
@ -121,9 +121,9 @@ DataImporter = {
|
||||
});
|
||||
|
||||
if (errors.length === 0) {
|
||||
transacting.commit();
|
||||
return;
|
||||
} else {
|
||||
transacting.rollback(errors);
|
||||
throw errors;
|
||||
}
|
||||
});
|
||||
}).then(function () {
|
||||
|
@ -8,7 +8,7 @@ const importOptions = {
|
||||
returnImportedData: true
|
||||
};
|
||||
|
||||
describe('Integration: Importer Legacy', function () {
|
||||
describe('Importer Legacy', function () {
|
||||
beforeEach(testUtils.teardownDb);
|
||||
beforeEach(testUtils.setup('roles', 'owner', 'settings'));
|
||||
|
@ -9,7 +9,7 @@ const importOptions = {
|
||||
returnImportedData: true
|
||||
};
|
||||
|
||||
describe('Integration: Importer 1.0', function () {
|
||||
describe('Importer 1.0', function () {
|
||||
beforeEach(testUtils.teardownDb);
|
||||
beforeEach(testUtils.setup('roles', 'owner', 'settings'));
|
||||
|
@ -24,7 +24,7 @@ const knex = db.knex;
|
||||
const {exportedBodyV2} = require('../../utils/fixtures/export/body-generator');
|
||||
|
||||
// Tests in here do an import for each test
|
||||
describe('Integration: Importer', function () {
|
||||
describe('Importer', function () {
|
||||
before(testUtils.teardownDb);
|
||||
|
||||
beforeEach(function () {
|
||||
@ -898,6 +898,11 @@ describe('Integration: Importer', function () {
|
||||
});
|
||||
|
||||
it('imports settings fields deprecated in v2 and removed in v3: slack hook, permalinks', function () {
|
||||
const EventRegistry = require('../../../core/server/lib/common/events');
|
||||
sinon.stub(EventRegistry, 'emit').callsFake((event) => {
|
||||
console.log('emitted event' + event);
|
||||
});
|
||||
|
||||
const exportData = exportedBodyV2().db[0];
|
||||
|
||||
exportData.data.settings[0] = testUtils.DataGenerator.forKnex.createSetting({
|
Loading…
Reference in New Issue
Block a user