Skip to content

Commit

Permalink
chore: default role can be set
Browse files Browse the repository at this point in the history
  • Loading branch information
frknasir committed Jul 18, 2022
1 parent c448c9e commit 6e1a149
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/persona.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
// 'permissions' => ['*'],
// ],
],

'default_role' => null,
];
2 changes: 1 addition & 1 deletion database/migrations/create_persona_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ return new class extends Migration
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('role')->nullable();
$table->string('role')->nullable()->default(config('persona.default_role'));
});
}

Expand Down
15 changes: 15 additions & 0 deletions tests/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@

expect($user->hasPermission('non-existing-permission'))->toBe(false);
});

test('a default role can be set', function () {
$user = UserWithRole::forceCreate([
'name' => 'Test User',
'email' => '[email protected]',
'password' => 'test',
'role' => 'cashier',
]);

expect($user->role)->toBe('cashier');
expect($user->hasRole('cashier'))->toBe(true);
expect($user->hasRole('owner'))->toBe(false);
expect($user->name)->toBe('Test User');
expect($user->email)->toBe('[email protected]');
});
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function getEnvironmentSetUp($app)
],
],
]);

config()->set('persona.default_role', 'cashier');
}

protected function setUpDatabase()
Expand Down

0 comments on commit 6e1a149

Please sign in to comment.