From ce337a305bfb8c20e5d5f36a7272d200a5b6d43c Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 30 Aug 2017 10:30:50 -0500 Subject: [PATCH] Added test for dupe parents ensure we do not create a duplicate post/category xref for duplicate parent categories --- test/scripts/models/post.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/scripts/models/post.js b/test/scripts/models/post.js index 69821fc046..e0dd933d2c 100644 --- a/test/scripts/models/post.js +++ b/test/scripts/models/post.js @@ -338,6 +338,19 @@ describe('Post', () => { return Post.removeById(post._id); })); + it('setCategories() - multiple hierarchies (dedupes repeated parent)', () => Post.insert({ + source: 'foo.md', + slug: 'bar' + }).then(post => post.setCategories([['foo', 'bar'], ['foo', 'baz']]) + .thenReturn(Post.findById(post._id))).then(post => { + var cats = post.categories.toArray(); + + // There should have been 3 categories set (foo is dupe) + cats.should.have.lengthOf(3); + + return Post.removeById(post._id); + })); + it('remove PostTag references when a post is removed', () => Post.insert({ source: 'foo.md', slug: 'bar'