@@ -411,7 +411,8 @@ describe('Post API', function () {
411
411
}
412
412
413
413
var updatedPost = res . body ;
414
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
414
+ // Require cache invalidation when post was updated and published
415
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
415
416
res . should . be . json ;
416
417
417
418
updatedPost . should . exist ;
@@ -458,7 +459,7 @@ describe('Post API', function () {
458
459
}
459
460
460
461
var putBody = res . body ;
461
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
462
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
462
463
res . should . be . json ;
463
464
putBody . should . exist ;
464
465
putBody . posts [ 0 ] . title . should . eql ( changedValue ) ;
@@ -469,6 +470,93 @@ describe('Post API', function () {
469
470
} ) ;
470
471
} ) ;
471
472
473
+ it ( 'can edit a new draft and update post' , function ( done ) {
474
+ var newTitle = 'My Post' ,
475
+ newTagName = 'My Tag' ,
476
+ publishedState = 'published' ,
477
+ newTag = { id : null , name : newTagName } ,
478
+ newPost = { posts : [ { status : 'draft' , title : newTitle , markdown : 'my post' , tags : [ newTag ] } ] } ;
479
+
480
+ request . post ( testUtils . API . getApiQuery ( 'posts/?include=tags' ) )
481
+ . set ( 'X-CSRF-Token' , csrfToken )
482
+ . send ( newPost )
483
+ . expect ( 201 )
484
+ . end ( function ( err , res ) {
485
+ if ( err ) {
486
+ return done ( err ) ;
487
+ }
488
+
489
+ res . should . be . json ;
490
+ var draftPost = res . body ;
491
+ res . headers [ 'location' ] . should . equal ( '/ghost/api/v0.1/posts/' + draftPost . posts [ 0 ] . id + '/?status=draft' ) ;
492
+ draftPost . posts . should . exist ;
493
+ draftPost . posts . length . should . be . above ( 0 ) ;
494
+ draftPost . posts [ 0 ] . title . should . eql ( newTitle ) ;
495
+ testUtils . API . checkResponse ( draftPost . posts [ 0 ] , 'post' ) ;
496
+
497
+ draftPost . posts [ 0 ] . title = 'Vote for Casper in red' ;
498
+
499
+ request . put ( testUtils . API . getApiQuery ( 'posts/' + draftPost . posts [ 0 ] . id + '/?include=tags' ) )
500
+ . set ( 'X-CSRF-Token' , csrfToken )
501
+ . send ( draftPost )
502
+ . expect ( 200 )
503
+ . end ( function ( err , res ) {
504
+ if ( err ) {
505
+ return done ( err ) ;
506
+ }
507
+
508
+ // Updating a draft should not send x-cache-invalidate headers
509
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
510
+ done ( ) ;
511
+ } ) ;
512
+ } ) ;
513
+ } ) ;
514
+
515
+ it ( 'can edit a new published post and unpublish' , function ( done ) {
516
+ var newTitle = 'My Post' ,
517
+ newTagName = 'My Tag' ,
518
+ draftState = 'draft' ,
519
+ newTag = { id : null , name : newTagName } ,
520
+ newPost = { posts : [ { status : 'published' , title : newTitle , markdown : 'my post' , tags : [ newTag ] } ] } ;
521
+
522
+ request . post ( testUtils . API . getApiQuery ( 'posts/?include=tags' ) )
523
+ . set ( 'X-CSRF-Token' , csrfToken )
524
+ . send ( newPost )
525
+ . expect ( 201 )
526
+ . end ( function ( err , res ) {
527
+ if ( err ) {
528
+ return done ( err ) ;
529
+ }
530
+
531
+ res . should . be . json ;
532
+ var draftPost = res . body ;
533
+ res . headers [ 'location' ] . should . equal ( '/ghost/api/v0.1/posts/' + draftPost . posts [ 0 ] . id + '/?status=published' ) ;
534
+ draftPost . posts . should . exist ;
535
+ draftPost . posts . length . should . be . above ( 0 ) ;
536
+ draftPost . posts [ 0 ] . title . should . eql ( newTitle ) ;
537
+ testUtils . API . checkResponse ( draftPost . posts [ 0 ] , 'post' ) ;
538
+
539
+ draftPost . posts [ 0 ] . title = 'Vote for Casper in red' ;
540
+ draftPost . posts [ 0 ] . status = draftState ;
541
+
542
+ request . put ( testUtils . API . getApiQuery ( 'posts/' + draftPost . posts [ 0 ] . id + '/?include=tags' ) )
543
+ . set ( 'X-CSRF-Token' , csrfToken )
544
+ . send ( draftPost )
545
+ . expect ( 200 )
546
+ . end ( function ( err , res ) {
547
+ if ( err ) {
548
+ return done ( err ) ;
549
+ }
550
+
551
+
552
+ var unpublishedPost = res . body ;
553
+ // Unpublishing a post should send x-cache-invalidate headers
554
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
555
+ done ( ) ;
556
+ } ) ;
557
+ } ) ;
558
+ } ) ;
559
+
472
560
it ( 'can change a post to a static page' , function ( done ) {
473
561
request . get ( testUtils . API . getApiQuery ( 'posts/1/?include=tags' ) )
474
562
. end ( function ( err , res ) {
@@ -492,7 +580,7 @@ describe('Post API', function () {
492
580
}
493
581
494
582
var putBody = res . body ;
495
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
583
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
496
584
res . should . be . json ;
497
585
putBody . should . exist ;
498
586
putBody . posts [ 0 ] . page . should . eql ( changedValue ) ;
@@ -527,7 +615,7 @@ describe('Post API', function () {
527
615
528
616
var putBody = res . body ;
529
617
530
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
618
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
531
619
res . should . be . json ;
532
620
putBody . should . exist ;
533
621
putBody . posts [ 0 ] . page . should . eql ( changedValue ) ;
@@ -615,7 +703,7 @@ describe('Post API', function () {
615
703
}
616
704
617
705
var putBody = res . body ;
618
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
706
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
619
707
res . should . be . json ;
620
708
putBody . should . exist ;
621
709
putBody . posts . should . exist ;
@@ -843,7 +931,7 @@ describe('Post API', function () {
843
931
yyyy = today . getFullYear ( ) ,
844
932
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/' + putBody . posts [ 0 ] . slug + '/' ;
845
933
846
- _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( false ) ;
934
+ _ . has ( res . headers , 'x-cache-invalidate' ) . should . equal ( true ) ;
847
935
res . should . be . json ;
848
936
putBody . should . exist ;
849
937
putBody . posts [ 0 ] . title . should . eql ( changedValue ) ;
0 commit comments