@@ -203,6 +203,26 @@ describe('Post', function() {
203203 } ) ;
204204 } ) ;
205205
206+ it ( 'setTags() - empty tag' , function ( ) {
207+ var id ;
208+
209+ return Post . insert ( {
210+ source : 'foo.md' ,
211+ slug : 'foo'
212+ } ) . then ( function ( post ) {
213+ id = post . _id ;
214+ return post . setTags ( [ '' , undefined , null , false , 0 , 'normal' ] ) ;
215+ } ) . then ( function ( ) {
216+ var post = Post . findById ( id ) ;
217+
218+ post . tags . map ( function ( tag ) {
219+ return tag . name ;
220+ } ) . should . eql ( [ 'false' , '0' , 'normal' ] ) ;
221+ } ) . finally ( function ( ) {
222+ return Post . removeById ( id ) ;
223+ } ) ;
224+ } ) ;
225+
206226 it ( 'setCategories() - old categories should be removed' , function ( ) {
207227 var id ;
208228
@@ -304,6 +324,46 @@ describe('Post', function() {
304324 } ) ;
305325 } ) ;
306326
327+ it ( 'setCategories() - empty category' , function ( ) {
328+ var id ;
329+
330+ return Post . insert ( {
331+ source : 'foo.md' ,
332+ slug : 'foo'
333+ } ) . then ( function ( post ) {
334+ id = post . _id ;
335+ return post . setCategories ( [ 'test' , null ] ) ;
336+ } ) . then ( function ( ) {
337+ var post = Post . findById ( id ) ;
338+
339+ post . categories . map ( function ( cat ) {
340+ return cat . name ;
341+ } ) . should . eql ( [ 'test' ] ) ;
342+ } ) . finally ( function ( ) {
343+ return Post . removeById ( id ) ;
344+ } ) ;
345+ } ) ;
346+
347+ it ( 'setCategories() - empty category in middle' , function ( ) {
348+ var id ;
349+
350+ return Post . insert ( {
351+ source : 'foo.md' ,
352+ slug : 'foo'
353+ } ) . then ( function ( post ) {
354+ id = post . _id ;
355+ return post . setCategories ( [ 'foo' , null , 'bar' ] ) ;
356+ } ) . then ( function ( ) {
357+ var post = Post . findById ( id ) ;
358+
359+ post . categories . map ( function ( cat ) {
360+ return cat . name ;
361+ } ) . should . eql ( [ 'foo' , 'bar' ] ) ;
362+ } ) . finally ( function ( ) {
363+ return Post . removeById ( id ) ;
364+ } ) ;
365+ } ) ;
366+
307367 it ( 'remove PostTag references when a post is removed' , function ( ) {
308368 return Post . insert ( {
309369 source : 'foo.md' ,
0 commit comments