Skip to content

Commit

Permalink
Merge pull request #3 from starfolksoftware/feat/2-default-role
Browse files Browse the repository at this point in the history
chore: default role can be set
  • Loading branch information
frknasir authored Jul 18, 2022
2 parents c448c9e + 12f179c commit 60fde85
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
coverage: none

- name: Install composer dependencies
Expand Down
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 60fde85

Please sign in to comment.