-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4c38bd
commit 0533ad7
Showing
11 changed files
with
176 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Project; | ||
|
||
class ProjectTasksController extends Controller | ||
{ | ||
/** | ||
* Add a task to the given project. | ||
* | ||
* @param \App\Project $project | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function store(Project $project) | ||
{ | ||
request()->validate(['body' => 'required']); | ||
|
||
$project->addTask(request('body')); | ||
|
||
return redirect($project->path()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Task extends Model | ||
{ | ||
/** | ||
* Attributes to guard against mass assignment. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(App\Task::class, function (Faker $faker) { | ||
return [ | ||
'body' => $faker->sentence | ||
]; | ||
}); |
33 changes: 33 additions & 0 deletions
33
database/migrations/2019_01_12_191142_create_tasks_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateTasksTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('tasks', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->unsignedInteger('project_id'); | ||
$table->text('body'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('tasks'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Project; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class ProjectTasksTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function guests_cannot_add_tasks_to_projects() | ||
{ | ||
$project = factory('App\Project')->create(); | ||
|
||
$this->post($project->path() . '/tasks')->assertRedirect('login'); | ||
} | ||
|
||
/** @test */ | ||
public function a_project_can_have_tasks() | ||
{ | ||
$this->signIn(); | ||
|
||
$project = auth()->user()->projects()->create( | ||
factory(Project::class)->raw() | ||
); | ||
|
||
$this->post($project->path() . '/tasks', ['body' => 'Test task']); | ||
|
||
$this->get($project->path()) | ||
->assertSee('Test task'); | ||
} | ||
|
||
/** @test */ | ||
public function a_task_requires_a_body() | ||
{ | ||
$this->signIn(); | ||
|
||
$project = auth()->user()->projects()->create( | ||
factory(Project::class)->raw() | ||
); | ||
|
||
$attributes = factory('App\Task')->raw(['body' => '']); | ||
|
||
$this->post($project->path() . '/tasks', $attributes)->assertSessionHasErrors('body'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters