Skip to content
Permalink
Browse files

Episode 29

  • Loading branch information...
JeffreyWay committed Feb 19, 2019
1 parent ad46117 commit a9131be0775430bbad1dd81447398ad4266fe918
@@ -82,6 +82,22 @@ public function update(Project $project)
return redirect($project->path());
}
/**
* Destroy the project.
*
* @param Project $project
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function destroy(Project $project)
{
$this->authorize('update', $project);
$project->delete();
return redirect('/projects');
}
/**
* Validate the request attributes.
*
@@ -51,7 +51,7 @@ protected static function recordableEvents()
return static::$recordableEvents;
}
return ['created', 'updated', 'deleted'];
return ['created', 'updated'];
}
/**
@@ -3,5 +3,13 @@
<a href="{{ $project->path() }}" class="text-black no-underline">{{ $project->title }}</a>
</h3>

<div class="text-grey">{{ str_limit($project->description, 100) }}</div>
<div class="text-grey mb-4">{{ str_limit($project->description, 100) }}</div>

<footer>
<form method="POST" action="{{ $project->path() }}" class="text-right">
@method('DELETE')
@csrf
<button type="submit" class="text-xs">Delete</button>
</form>
</footer>
</div>
@@ -16,12 +16,7 @@
});
Route::group(['middleware' => 'auth'], function () {
Route::get('/projects', 'ProjectsController@index');
Route::get('/projects/create', 'ProjectsController@create');
Route::get('/projects/{project}', 'ProjectsController@show');
Route::get('/projects/{project}/edit', 'ProjectsController@edit');
Route::patch('/projects/{project}', 'ProjectsController@update');
Route::post('/projects', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
Route::post('/projects/{project}/tasks', 'ProjectTasksController@store');
Route::patch('/projects/{project}/tasks/{task}', 'ProjectTasksController@update');
@@ -49,6 +49,32 @@ public function a_user_can_create_a_project()
->assertSee($attributes['notes']);
}
/** @test */
function unauthorized_users_cannot_delete_projects()
{
$project = ProjectFactory::create();
$this->delete($project->path())
->assertRedirect('/login');
$this->signIn();
$this->delete($project->path())
->assertStatus(403);
}
/** @test */
function a_user_can_delete_a_project()
{
$project = ProjectFactory::create();
$this->actingAs($project->owner)
->delete($project->path())
->assertRedirect('/projects');
$this->assertDatabaseMissing('projects', $project->only('id'));
}
/** @test */
function a_user_can_update_a_project()
{

0 comments on commit a9131be

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