Skip to content

Commit

Permalink
Fixes #26 - set default values for custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tatebosler committed Jul 16, 2018
1 parent 5201168 commit 7be607b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/Listeners/FillShowDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function handle(ShowCreating $event)
foreach($arrays as $array) {
$show->{$array} = [];
}
$custom = ['content', 'scheduling', 'etc'];
foreach($custom as $key) {
$fields = collect($show->track->{$key})->pluck('db')->all();
$show->{$key} = array_fill_keys($fields, '');
}

$show->description = $show->description ?? '';
$show->title = $show->title ?? $show->track->name.' Show';
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/ShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,29 @@ public function testContentViewRenders()
$request->assertOk()
->assertViewIs('shows.content');
}

/**
* Test that tracks with custom fields can still render okay.
*
* @return void
*/
public function testCustomFieldTracksStillRender()
{
$track = factory(Track::class)->create([
'active' => true,
'content' => [
['db' => 'sponsor', 'title' => 'Sponsor', 'helptext' => null, 'type' => 'shorttext', 'rules' => ['required', 'min:3']]
]
]);
$show = factory(Show::class)->create([
'term_id' => $this->term->id,
'track_id' => $track->id
]);

$request = $this->get("/shows/{$show->id}/content");

$request->assertOk()
->assertViewIs('shows.content')
->assertSee('Sponsor');
}
}

0 comments on commit 7be607b

Please sign in to comment.