Permalink
Browse files

Episode 82

  • Loading branch information...
JeffreyWay committed Oct 3, 2017
1 parent e459e7f commit d7a612ef23edee3e970c6418f930ce7ec72a6e1a
@@ -24,6 +24,11 @@ public function up()
$table->text('body');
$table->unsignedInteger('best_reply_id')->nullable();
$table->timestamps();
$table->foreign('best_reply_id')
->references('id')
->on('replies')
->onDelete('set null');
});
}
@@ -28,7 +28,7 @@
Route::get('/threads/{channel}/{thread}/replies', 'RepliesController@index');
Route::post('/threads/{channel}/{thread}/replies', 'RepliesController@store');
Route::patch('/replies/{reply}', 'RepliesController@update');
Route::delete('/replies/{reply}', 'RepliesController@destroy');
Route::delete('/replies/{reply}', 'RepliesController@destroy')->name('replies.destroy');
Route::post('/replies/{reply}/best', 'BestRepliesController@store')->name('best-replies.store');
@@ -43,5 +43,17 @@ function only_the_thread_creator_may_mark_a_reply_as_best()
$this->assertFalse($replies[1]->fresh()->isBest());
}
/** @test */
function if_a_best_reply_is_deleted_then_the_thread_is_properly_updated_to_reflect_that()
{
$this->signIn();
$reply = create('App\Reply', ['user_id' => auth()->id()]);
$reply->thread->markBestReply($reply);
$this->deleteJson(route('replies.destroy', $reply));
$this->assertNull($reply->thread->fresh()->best_reply_id);
}
}
@@ -5,6 +5,7 @@
use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\DB;
abstract class TestCase extends BaseTestCase
{
@@ -14,6 +15,8 @@ protected function setUp()
{
parent::setUp();
DB::statement('PRAGMA foreign_keys=on;');
$this->disableExceptionHandling();
}

0 comments on commit d7a612e

Please sign in to comment.