mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-14 19:53:12 +00:00
109 - Autopublishing New Concerts
This commit is contained in:
@@ -20,6 +20,16 @@ class Concert extends Model
|
|||||||
return $query->whereNotNull('published_at');
|
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()
|
public function getFormattedDateAttribute()
|
||||||
{
|
{
|
||||||
return $this->date->format('F j, Y');
|
return $this->date->format('F j, Y');
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class ConcertsController extends Controller
|
|||||||
'ticket_price' => request('ticket_price') * 100,
|
'ticket_price' => request('ticket_price') * 100,
|
||||||
])->addTickets(request('ticket_quantity'));
|
])->addTickets(request('ticket_quantity'));
|
||||||
|
|
||||||
|
$concert->publish();
|
||||||
|
|
||||||
return redirect()->route('concerts.show', $concert);
|
return redirect()->route('concerts.show', $concert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ class AddConcertTest extends TestCase
|
|||||||
|
|
||||||
$this->assertTrue($concert->user->is($user));
|
$this->assertTrue($concert->user->is($user));
|
||||||
|
|
||||||
|
$this->assertTrue($concert->isPublished());
|
||||||
|
|
||||||
$this->assertEquals('No Warning', $concert->title);
|
$this->assertEquals('No Warning', $concert->title);
|
||||||
$this->assertEquals('with Cruel Hand and Backtrack', $concert->subtitle);
|
$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);
|
$this->assertEquals("You must be 19 years of age to attend this concert.", $concert->additional_information);
|
||||||
|
|||||||
@@ -58,6 +58,17 @@ class ConcertTest extends TestCase
|
|||||||
$this->assertFalse($publishedConcerts->contains($unpublishedConcert));
|
$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 */
|
/** @test */
|
||||||
function can_add_tickets()
|
function can_add_tickets()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user