Skip to content

Commit

Permalink
-whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljsummers committed Aug 30, 2017
1 parent ac5ce4e commit 3f45e26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = function(ctx) {
).map(cat =>
Array.isArray(cat) ? removeEmptyTag(cat) : cat + ''
);

var PostCategory = ctx.model('PostCategory');
var Category = ctx.model('Category');
var id = this._id;
Expand All @@ -159,24 +159,24 @@ module.exports = function(ctx) {
name: cat,
parent: i ? parentIds[i - 1] : {$exists: false}
}, {lean: true});

if (data) {
allIds.push(data._id);
parentIds.push(data._id);
return data;
}

// Insert the category if not exist
var obj = {name: cat};
if (i) obj.parent = parentIds[i - 1];

return Category.insert(obj).catch(err => {
// Try to find the category again. Throw the error if not found
var data = Category.findOne({
name: cat,
parent: i ? parentIds[i - 1] : {$exists: false}
}, {lean: true});

if (data) return data;
throw err;
}).then(data => {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function(ctx) {
var info = parseFilename(config.new_post_name, path);
var keys = Object.keys(info);
var key;

data.source = file.path;
data.raw = content;
data.slug = info.title;
Expand Down
6 changes: 3 additions & 3 deletions test/scripts/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Post', () => {
}).then(post => post.setCategories(['foo', 'bar', 'baz'])
.thenReturn(Post.findById(post._id))).then(post => {
var cats = post.categories;

// Make sure the order of categories is correct
cats.map((cat, i) => {
// Make sure the parent reference is correct
Expand Down Expand Up @@ -326,11 +326,11 @@ describe('Post', () => {
// Category 1 should be foo, no parent
cats[0].name.should.eql('foo');
should.not.exist(cats[0].parent);

// Category 2 should be bar, foo as parent
cats[1].name.should.eql('bar');
cats[1].parent.should.eql(cats[0]._id);

// Category 3 should be baz, no parent
cats[2].name.should.eql('baz');
should.not.exist(cats[2].parent);
Expand Down

0 comments on commit 3f45e26

Please sign in to comment.