mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fix delete button
closes #2492 - added when.all() to wait until all posts are deleted before deleting tags - added a test
This commit is contained in:
parent
ae3c36797a
commit
b83fc25613
2 changed files with 62 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
var migrations = require('../data/migration'),
|
var migrations = require('../data/migration'),
|
||||||
_ = require('lodash');
|
_ = require('lodash'),
|
||||||
|
when = require('when');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Post: require('./post').Post,
|
Post: require('./post').Post,
|
||||||
|
@ -20,14 +21,14 @@ module.exports = {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return self.Post.browse().then(function (posts) {
|
return self.Post.browse().then(function (posts) {
|
||||||
_.each(posts.toJSON(), function (post) {
|
return when.all(_.map(posts.toJSON(), function (post) {
|
||||||
self.Post.destroy(post.id);
|
return self.Post.destroy(post.id);
|
||||||
});
|
}));
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
self.Tag.browse().then(function (tags) {
|
return self.Tag.browse().then(function (tags) {
|
||||||
_.each(tags.toJSON(), function (tag) {
|
return when.all(_.map(tags.toJSON(), function (tag) {
|
||||||
self.Tag.destroy(tag.id);
|
return self.Tag.destroy(tag.id);
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
53
core/test/integration/api/api_db_spec.js
Normal file
53
core/test/integration/api/api_db_spec.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*globals describe, before, beforeEach, afterEach, it */
|
||||||
|
var testUtils = require('../../utils'),
|
||||||
|
should = require('should'),
|
||||||
|
|
||||||
|
// Stuff we are testing
|
||||||
|
DataGenerator = require('../../utils/fixtures/data-generator'),
|
||||||
|
dbAPI = require('../../../server/api/db');
|
||||||
|
TagsAPI = require('../../../server/api/tags');
|
||||||
|
PostAPI = require('../../../server/api/posts');
|
||||||
|
|
||||||
|
describe('DB API', function () {
|
||||||
|
|
||||||
|
before(function (done) {
|
||||||
|
testUtils.clearData().then(function () {
|
||||||
|
done();
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(function (done) {
|
||||||
|
testUtils.initData()
|
||||||
|
.then(function () {
|
||||||
|
return testUtils.insertDefaultFixtures();
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
done();
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function (done) {
|
||||||
|
testUtils.clearData().then(function () {
|
||||||
|
done();
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete all content', function (done) {
|
||||||
|
|
||||||
|
dbAPI.deleteAllContent().then(function (result){
|
||||||
|
should.exist(result.message);
|
||||||
|
result.message.should.equal('Successfully deleted all content from your blog.')
|
||||||
|
}).then(function () {
|
||||||
|
TagsAPI.browse().then(function (results) {
|
||||||
|
should.exist(results);
|
||||||
|
results.length.should.equal(0);
|
||||||
|
});
|
||||||
|
}).then(function () {
|
||||||
|
PostAPI.browse().then(function (results) {
|
||||||
|
should.exist(results);
|
||||||
|
results.posts.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).then(null, done);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue