diff --git a/app/Http/Controllers/ConcertsController.php b/app/Http/Controllers/ConcertsController.php index b946790..ae93cf3 100644 --- a/app/Http/Controllers/ConcertsController.php +++ b/app/Http/Controllers/ConcertsController.php @@ -9,7 +9,7 @@ class ConcertsController extends Controller { public function show($id) { - $concert = Concert::find($id); + $concert = Concert::whereNotNull('published_at')->findOrFail($id); return view('concerts.show', ['concert' => $concert]); } } diff --git a/database/migrations/2016_11_01_200307_create_concerts_table.php b/database/migrations/2016_11_01_200307_create_concerts_table.php index fa5f69c..f7e98e5 100644 --- a/database/migrations/2016_11_01_200307_create_concerts_table.php +++ b/database/migrations/2016_11_01_200307_create_concerts_table.php @@ -25,6 +25,7 @@ class CreateConcertsTable extends Migration $table->string('state'); $table->string('zip'); $table->text('additional_information'); + $table->datetime('published_at')->nullable(); $table->timestamps(); }); } diff --git a/tests/features/ViewConcertListingTest.php b/tests/features/ViewConcertListingTest.php index 0ee6629..5a774cc 100644 --- a/tests/features/ViewConcertListingTest.php +++ b/tests/features/ViewConcertListingTest.php @@ -13,8 +13,6 @@ class ViewConcertListingTest extends TestCase /** @test */ function user_can_view_a_concert_listing() { - // Arrange - // Create a concert $concert = Concert::create([ 'title' => 'The Red Chord', 'subtitle' => 'with Animosity and Lethargy', @@ -28,12 +26,8 @@ class ViewConcertListingTest extends TestCase 'additional_information' => 'For tickets, call (555) 555-5555.', ]); - // Act - // View the concert listing $this->visit('/concerts/'.$concert->id); - // Assert - // See the concert details $this->see('The Red Chord'); $this->see('with Animosity and Lethargy'); $this->see('December 13, 2016'); @@ -44,4 +38,16 @@ class ViewConcertListingTest extends TestCase $this->see('Laraville, ON 17916'); $this->see('For tickets, call (555) 555-5555.'); } + + /** @test */ + function user_cannot_view_unpublished_concert_listings() + { + $concert = factory(Concert::class)->create([ + 'published_at' => null, + ]); + + $this->get('/concerts/'.$concert->id); + + $this->assertResponseStatus(404); + } }