Skip to content

Commit

Permalink
Dusk tests, policies, prose, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgilmore committed Dec 16, 2017
1 parent a3db6d4 commit e6fdd2a
Show file tree
Hide file tree
Showing 19 changed files with 508 additions and 368 deletions.
4 changes: 2 additions & 2 deletions .env.dusk.local
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ APP_ENV=local
APP_KEY=3bjdgUGwDCb1NTcONMKdFCqhvn1ek1Qu
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://hackerpair.dev
APP_URL=http://hackerpair.test

DB_CONNECTION=mysql
DB_HOST=local.mysql.com
DB_HOST=10.1.1.33
DB_PORT=3306
DB_DATABASE=test_hackerpair
DB_USERNAME=homestead
Expand Down
2 changes: 2 additions & 0 deletions app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Event extends Model
use Sluggable,
SluggableScopeHelpers;

protected $published = false;

protected $dates = [
'created_at',
'start_date',
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
class EventsController extends Controller
{

public function __construct()
{
$this->middleware('auth')->only(['create','store','edit','update','destroy']);
}

/**
* Display a listing of the resource.
*
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/UserHostedEventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
class UserHostedEventsController extends Controller
{

public function __construct()
{
$this->authorizeResource(\App\Event::class);
}

public function index(User $user)
{
$events = $user->hostedEvents()->paginate();
Expand Down
20 changes: 18 additions & 2 deletions app/Http/Requests/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ public function rules()

return [
'name' => 'required|min:10|max:50',
'category_id' => 'required|integer',
'max_attendees' => 'required|integer',
'start_date' => 'required',
'start_time' => 'required',
'description' => 'required'
'oneliner' => 'required|min:10|max:50',
'description' => 'required',
'venue' => 'required',
'street' => 'required',
'city' => 'required',
'state_id' => 'required|integer',
'zip' => 'required'
];
}

Expand All @@ -43,8 +50,17 @@ public function messages()
'max_attendees.required' => 'What is the maximum number of attendees allowed to attend your event?',
'name.min' => 'Event names must consist of at least 10 characters',
'name.max' => 'Event names cannot be longer than 50 characters',
'oneliner.required' => 'Please assign a one line event description',
'oneliner.min' => 'The oneline description should consist of more than 10 characters',
'oneliner.max' => 'The oneline description should consist of less than 50 characters',
'start_date.required' => 'Please provide an event date',
'start_time.required' => 'Please provide an event starting time'
'start_time.required' => 'Please provide an event starting time',
'description.required' => 'Please provide a description',
'venue.required' => 'Please provide a venue name (Pizza Cafe, Bob\'s Bar, etc.)',
'street.required' => 'Please provide the venue\'s street address',
'city.required' => 'Please provide the venue\'s city',
'state_id.required' => 'Please provide the venue\'s state (Ohio, etc)',
'zip.required' => 'Please provide the venue\'s zip code'
];

}
Expand Down
38 changes: 38 additions & 0 deletions app/Policies/EventPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Policies;

use Illuminate\Support\Facades\Auth;

use App\User;
use App\Event;
use Illuminate\Auth\Access\HandlesAuthorization;

class EventPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can create events.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user)
{
return $user->id > 0;
}

/**
* Determine whether the user can update the event.
*
* @param \App\User $user
* @param \App\Event $event
* @return mixed
*/
public function update(User $user, Event $event)
{
return $user->id == $event->user_id;
}

}
2 changes: 1 addition & 1 deletion app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class AccountPolicy
class UserPolicy
{
use HandlesAuthorization;

Expand Down
5 changes: 2 additions & 3 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Providers;

use App\Policies\AccountPolicy;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

Expand All @@ -15,7 +13,8 @@ class AuthServiceProvider extends ServiceProvider
* @var array
*/
protected $policies = [
'App\User' => 'App\Policies\AccountPolicy',
'App\User' => 'App\Policies\UserPolicy',
'App\Event' => 'App\Policies\EventPolicy',
];

/**
Expand Down
9 changes: 9 additions & 0 deletions database/factories/CategoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Faker\Generator as Faker;

$factory->define(App\Category::class, function (Faker $faker) {
return [
'name' => 'PHP'
];
});
10 changes: 10 additions & 0 deletions database/factories/StateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Faker\Generator as Faker;

$factory->define(App\State::class, function (Faker $faker) {
return [
'name' => 'Ohio',
'abbreviation' => 'OH'
];
});
Loading

0 comments on commit e6fdd2a

Please sign in to comment.