Skip to content

Commit

Permalink
Episode 29
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed Feb 19, 2019
1 parent ad46117 commit a9131be
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/ProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion app/RecordsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected static function recordableEvents()
return static::$recordableEvents;
}

return ['created', 'updated', 'deleted'];
return ['created', 'updated'];
}

/**
Expand Down
10 changes: 9 additions & 1 deletion resources/views/projects/card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 1 addition & 6 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/ManageProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit a9131be

Please sign in to comment.