Permalink
Browse files

Episode 84

  • Loading branch information...
JeffreyWay committed Oct 11, 2017
1 parent 558f664 commit 1172048298951ec56796389ec907ab4501549290
@@ -37,6 +37,10 @@ public function index($channelId, Thread $thread)
*/
public function store($channelId, Thread $thread, CreatePostRequest $form)
{
if ($thread->locked) {
return response('Thread is locked', 422);
}
return $thread->addReply([
'body' => request('body'),
'user_id' => auth()->id()
@@ -103,6 +103,14 @@ public function addReply($reply)
return $reply;
}
/**
* Lock the thread.
*/
public function lock()
{
$this->update(['locked' => true]);
}
/**
* Apply all relevant thread filters.
*
@@ -45,7 +45,8 @@
'title' => $title,
'body' => $faker->paragraph,
'visits' => 0,
'slug' => str_slug($title)
'slug' => str_slug($title),
'locked' => false
];
});
@@ -23,6 +23,7 @@ public function up()
$table->string('title');
$table->text('body');
$table->unsignedInteger('best_reply_id')->nullable();
$table->boolean('locked')->default(false);
$table->timestamps();
$table->foreign('best_reply_id')
@@ -0,0 +1,26 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class LockThreadsTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function an_adminstrator_can_lock_any_thread()
{
$this->signIn();
$thread = create('App\Thread');
$thread->lock();
$this->post($thread->path() . '/replies', [
'body' => 'Foobar',
'user_id' => auth()->id()
])->assertStatus(422);
}
}
@@ -133,4 +133,14 @@ function a_thread_can_check_if_the_authenticated_user_has_read_all_replies()
$this->assertFalse($thread->hasUpdatesFor($user));
});
}
/** @test */
function a_thread_may_be_locked()
{
$this->assertFalse($this->thread->locked);
$this->thread->lock();
$this->assertTrue($this->thread->locked);
}
}

0 comments on commit 1172048

Please sign in to comment.