Skip to content
Permalink
Browse files

Episode 22 Complete

  • Loading branch information...
JeffreyWay committed Jan 29, 2019
1 parent 1ab3d06 commit d2e4e82eb0855483fcd6437d0caceed2a1eaf9b6
@@ -37,13 +37,11 @@ public function update(Project $project, Task $task)
{
$this->authorize('update', $task->project);
request()->validate(['body' => 'required']);
$task->update(request()->validate(['body' => 'required']));
$task->update(['body' => request('body')]);
$method = request('completed') ? 'complete' : 'incomplete';
if (request()->has('completed')) {
$task->complete();
}
$task->$method();
return redirect($project->path());
}
@@ -57,14 +57,11 @@ public function addTask($body)
/**
* Record activity for a project.
*
* @param string $type
* @param string $description
*/
public function recordActivity($type)
public function recordActivity($description)
{
Activity::create([
'project_id' => $this->id,
'description' => $type
]);
$this->activity()->create(compact('description'));
}
/**
@@ -51,6 +51,14 @@ public function complete()
$this->project->recordActivity('completed_task');
}
/**
* Mark the task as incomplete.
*/
public function incomplete()
{
$this->update(['completed' => false]);
}
/**
* Get the owning project.
*
@@ -64,6 +64,21 @@ function a_task_can_be_updated()
$this->actingAs($project->owner)
->patch($project->tasks[0]->path(), [
'body' => 'changed'
]);
$this->assertDatabaseHas('tasks', [
'body' => 'changed'
]);
}
/** @test */
function a_task_can_be_completed()
{
$project = ProjectFactory::withTasks(1)->create();
$this->actingAs($project->owner)
->patch($project->tasks[0]->path(), [
'body' => 'changed',
'completed' => true
]);
@@ -74,6 +89,30 @@ function a_task_can_be_updated()
]);
}
/** @test */
function a_task_can_be_marked_as_incomplete()
{
$this->withoutExceptionHandling();
$project = ProjectFactory::withTasks(1)->create();
$this->actingAs($project->owner)
->patch($project->tasks[0]->path(), [
'body' => 'changed',
'completed' => true
]);
$this->patch($project->tasks[0]->path(), [
'body' => 'changed',
'completed' => false
]);
$this->assertDatabaseHas('tasks', [
'body' => 'changed',
'completed' => false
]);
}
/** @test */
public function a_task_requires_a_body()
{
@@ -38,4 +38,16 @@ function it_can_be_completed()
$this->assertTrue($task->fresh()->completed);
}
/** @test */
function it_can_be_marked_as_incomplete()
{
$task = factory(Task::class)->create(['completed' => true]);
$this->assertTrue($task->completed);
$task->incomplete();
$this->assertFalse($task->fresh()->completed);
}
}

0 comments on commit d2e4e82

Please sign in to comment.
You can’t perform that action at this time.