Correct post deletion spec so it is async

This commit is contained in:
Sam 2017-07-28 10:50:18 -04:00
parent 64d54bc549
commit a13d146251
2 changed files with 15 additions and 12 deletions

View File

@ -159,6 +159,7 @@ const Post = RestModel.extend({
done elsewhere.
**/
setDeletedState(deletedBy) {
let promise;
this.set('oldCooked', this.get('cooked'));
// Moderators can delete posts. Users can only trigger a deleted at message, unless delete_removed_posts_after is 0.
@ -169,8 +170,7 @@ const Post = RestModel.extend({
can_delete: false
});
} else {
cookAsync(I18n.t("post.deleted_by_author", {count: Discourse.SiteSettings.delete_removed_posts_after})).then(cooked => {
promise = cookAsync(I18n.t("post.deleted_by_author", {count: Discourse.SiteSettings.delete_removed_posts_after})).then(cooked => {
this.setProperties({
cooked: cooked,
can_delete: false,
@ -181,6 +181,8 @@ const Post = RestModel.extend({
});
});
}
return promise || Em.RSVP.Promise.resolve();
},
/**
@ -203,11 +205,12 @@ const Post = RestModel.extend({
},
destroy(deletedBy) {
this.setDeletedState(deletedBy);
return this.setDeletedState(deletedBy).then(()=>{
return ajax("/posts/" + this.get('id'), {
data: { context: window.location.pathname },
type: 'DELETE'
});
});
},
/**

View File

@ -64,9 +64,9 @@ QUnit.test('destroy by non-staff', assert => {
user = Discourse.User.create({username: 'evil trout'}),
post = buildPost({user: user, cooked: originalCooked});
post.destroy(user);
return post.destroy(user).then(() => {
assert.ok(!post.get('can_delete'), "the post can't be deleted again in this session");
assert.ok(post.get('cooked') !== originalCooked, "the cooked content changed");
assert.equal(post.get('version'), 2, "the version number increased");
});
});