From a59e0e21a23c8b386984acba06a75e81951cd9ec Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Tue, 4 Jul 2017 11:02:04 -0400 Subject: [PATCH] 120 - Creating Tickets at Time of Publish --- app/Concert.php | 1 + app/Http/Controllers/Backstage/ConcertsController.php | 3 ++- tests/Feature/Backstage/AddConcertTest.php | 1 + tests/Unit/ConcertTest.php | 7 ++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Concert.php b/app/Concert.php index 6ee6f9b..aeb5e49 100644 --- a/app/Concert.php +++ b/app/Concert.php @@ -28,6 +28,7 @@ class Concert extends Model public function publish() { $this->update(['published_at' => $this->freshTimestamp()]); + $this->addTickets($this->ticket_quantity); } public function getFormattedDateAttribute() diff --git a/app/Http/Controllers/Backstage/ConcertsController.php b/app/Http/Controllers/Backstage/ConcertsController.php index acebcca..66f11b4 100644 --- a/app/Http/Controllers/Backstage/ConcertsController.php +++ b/app/Http/Controllers/Backstage/ConcertsController.php @@ -49,7 +49,8 @@ class ConcertsController extends Controller 'state' => request('state'), 'zip' => request('zip'), 'ticket_price' => request('ticket_price') * 100, - ])->addTickets(request('ticket_quantity')); + 'ticket_quantity' => (int) request('ticket_quantity'), + ]); $concert->publish(); diff --git a/tests/Feature/Backstage/AddConcertTest.php b/tests/Feature/Backstage/AddConcertTest.php index addaaf3..035ce32 100644 --- a/tests/Feature/Backstage/AddConcertTest.php +++ b/tests/Feature/Backstage/AddConcertTest.php @@ -89,6 +89,7 @@ class AddConcertTest extends TestCase $this->assertEquals('ON', $concert->state); $this->assertEquals('12345', $concert->zip); $this->assertEquals(3250, $concert->ticket_price); + $this->assertEquals(75, $concert->ticket_quantity); $this->assertEquals(75, $concert->ticketsRemaining()); }); } diff --git a/tests/Unit/ConcertTest.php b/tests/Unit/ConcertTest.php index 0413f07..69f3eeb 100644 --- a/tests/Unit/ConcertTest.php +++ b/tests/Unit/ConcertTest.php @@ -61,12 +61,17 @@ class ConcertTest extends TestCase /** @test */ function concerts_can_be_published() { - $concert = factory(Concert::class)->create(['published_at' => null]); + $concert = factory(Concert::class)->create([ + 'published_at' => null, + 'ticket_quantity' => 5, + ]); $this->assertFalse($concert->isPublished()); + $this->assertEquals(0, $concert->ticketsRemaining()); $concert->publish(); $this->assertTrue($concert->isPublished()); + $this->assertEquals(5, $concert->ticketsRemaining()); } /** @test */