109 - Autopublishing New Concerts

This commit is contained in:
Adam Wathan
2017-05-25 12:44:30 -04:00
parent fc6389ca01
commit 9e15fbddf5
4 changed files with 25 additions and 0 deletions

View File

@@ -20,6 +20,16 @@ class Concert extends Model
return $query->whereNotNull('published_at');
}
public function isPublished()
{
return $this->published_at !== null;
}
public function publish()
{
$this->update(['published_at' => $this->freshTimestamp()]);
}
public function getFormattedDateAttribute()
{
return $this->date->format('F j, Y');

View File

@@ -46,6 +46,8 @@ class ConcertsController extends Controller
'ticket_price' => request('ticket_price') * 100,
])->addTickets(request('ticket_quantity'));
$concert->publish();
return redirect()->route('concerts.show', $concert);
}
}

View File

@@ -83,6 +83,8 @@ class AddConcertTest extends TestCase
$this->assertTrue($concert->user->is($user));
$this->assertTrue($concert->isPublished());
$this->assertEquals('No Warning', $concert->title);
$this->assertEquals('with Cruel Hand and Backtrack', $concert->subtitle);
$this->assertEquals("You must be 19 years of age to attend this concert.", $concert->additional_information);

View File

@@ -58,6 +58,17 @@ class ConcertTest extends TestCase
$this->assertFalse($publishedConcerts->contains($unpublishedConcert));
}
/** @test */
function concerts_can_be_published()
{
$concert = factory(Concert::class)->create(['published_at' => null]);
$this->assertFalse($concert->isPublished());
$concert->publish();
$this->assertTrue($concert->isPublished());
}
/** @test */
function can_add_tickets()
{