Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 fix issue with re-uploading a deleted theme (#725)
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#8515

- ensure the theme record is removed from the store when deleting because theme IDs get re-used unlike other models
  • Loading branch information
kevinansfield authored and kirrg001 committed Jun 1, 2017
1 parent 9069318 commit d2a7466
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/settings/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export default Controller.extend({
return;
}

return theme.destroyRecord().catch((error) => {
return theme.destroyRecord().then(() => {
// HACK: this is a private method, we need to unload from the store
// here so that uploading another theme with the same "id" doesn't
// attempt to update the deleted record
theme.unloadRecord();
}).catch((error) => {
this.get('notifications').showAPIError(error);
});
},
Expand Down
26 changes: 26 additions & 0 deletions tests/acceptance/settings/design-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,5 +651,31 @@ describe('Acceptance: Settings - Design', function () {
// restore default mirage handlers
mockThemes(server);
});

it('can delete then re-upload the same theme', async function () {
server.loadFixtures('themes');

// mock theme upload to emulate uploading theme with same id
server.post('/themes/upload/', function ({themes}) {
let theme = themes.create({
name: 'foo',
package: {
name: 'Foo',
version: '0.1'
}
});

return {themes: [theme]};
});

await visit('/settings/design');
await click(`${testSelector('theme-id', 'foo')} ${testSelector('theme-delete-button')}`);
await click(`.fullscreen-modal ${testSelector('delete-button')}`);

await click(testSelector('upload-theme-button'));
await fileUpload('.fullscreen-modal input[type="file"]', ['test'], {name: 'foo.zip', type: 'application/zip'});
// this will fail if upload failed because there won't be an activate now button
await click(`.fullscreen-modal ${testSelector('activate-now-button')}`);
});
});
});

0 comments on commit d2a7466

Please sign in to comment.