forked from spatie/laravel-permission
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix detaching user models on teams feature spatie#2220
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,32 @@ class TeamHasRolesTest extends HasRolesTest | |
/** @var bool */ | ||
protected $hasTeams = true; | ||
|
||
/** @test */ | ||
public function it_deletes_pivot_table_entries_when_deleting_models() | ||
{ | ||
$user1 = User::create(['email' => '[email protected]']); | ||
$user2 = User::create(['email' => '[email protected]']); | ||
|
||
setPermissionsTeamId(1); | ||
$user1->assignRole('testRole'); | ||
$user1->givePermissionTo('edit-articles'); | ||
$user2->assignRole('testRole'); | ||
$user2->givePermissionTo('edit-articles'); | ||
setPermissionsTeamId(2); | ||
$user1->givePermissionTo('edit-news'); | ||
|
||
$this->assertDatabaseHas('model_has_permissions', [config('permission.column_names.model_morph_key') => $user1->id]); | ||
$this->assertDatabaseHas('model_has_roles', [config('permission.column_names.model_morph_key') => $user1->id]); | ||
|
||
$user1->delete(); | ||
|
||
setPermissionsTeamId(1); | ||
$this->assertDatabaseMissing('model_has_permissions', [config('permission.column_names.model_morph_key') => $user1->id]); | ||
$this->assertDatabaseMissing('model_has_roles', [config('permission.column_names.model_morph_key') => $user1->id]); | ||
$this->assertDatabaseHas('model_has_permissions', [config('permission.column_names.model_morph_key') => $user2->id]); | ||
$this->assertDatabaseHas('model_has_roles', [config('permission.column_names.model_morph_key') => $user2->id]); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_assign_same_and_different_roles_on_same_user_different_teams() | ||
{ | ||
|