1.6 - Hiding Unpublished Concerts

This commit is contained in:
Adam Wathan
2016-11-03 10:37:51 -04:00
parent eef25ae099
commit 1a5f7c7e89
3 changed files with 14 additions and 7 deletions

View File

@@ -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]);
}
}

View File

@@ -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();
});
}

View File

@@ -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);
}
}