-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #975 from drbyte/fix-sync-saved-callback-bug
Add fix for broken sync saved event
- Loading branch information
Showing
4 changed files
with
76 additions
and
5 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 |
---|---|---|
|
@@ -449,4 +449,34 @@ public function it_can_sync_permissions_to_a_model_that_is_not_persisted() | |
$this->assertTrue($user->hasPermissionTo('edit-articles')); | ||
$this->assertTrue($user->fresh()->hasPermissionTo('edit-articles')); | ||
} | ||
|
||
/** @test */ | ||
public function calling_givePermissionTo_before_saving_object_doesnt_interfere_with_other_objects() | ||
{ | ||
$user = new User(['email' => '[email protected]']); | ||
$user->givePermissionTo('edit-news'); | ||
$user->save(); | ||
|
||
$user2 = new User(['email' => '[email protected]']); | ||
$user2->givePermissionTo('edit-articles'); | ||
$user2->save(); | ||
|
||
$this->assertTrue($user2->fresh()->hasPermissionTo('edit-articles')); | ||
$this->assertFalse($user2->fresh()->hasPermissionTo('edit-news')); | ||
} | ||
|
||
/** @test */ | ||
public function calling_syncPermissions_before_saving_object_doesnt_interfere_with_other_objects() | ||
{ | ||
$user = new User(['email' => '[email protected]']); | ||
$user->syncPermissions('edit-news'); | ||
$user->save(); | ||
|
||
$user2 = new User(['email' => '[email protected]']); | ||
$user2->syncPermissions('edit-articles'); | ||
$user2->save(); | ||
|
||
$this->assertTrue($user2->fresh()->hasPermissionTo('edit-articles')); | ||
$this->assertFalse($user2->fresh()->hasPermissionTo('edit-news')); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -200,6 +200,36 @@ public function it_will_sync_roles_to_a_model_that_is_not_persisted() | |
$this->assertTrue($user->hasRole($this->testUserRole)); | ||
} | ||
|
||
/** @test */ | ||
public function calling_syncRoles_before_saving_object_doesnt_interfere_with_other_objects() | ||
{ | ||
$user = new User(['email' => '[email protected]']); | ||
$user->syncRoles('testRole'); | ||
$user->save(); | ||
|
||
$user2 = new User(['email' => '[email protected]']); | ||
$user2->syncRoles('testRole2'); | ||
$user2->save(); | ||
|
||
$this->assertTrue($user2->fresh()->hasRole('testRole2')); | ||
$this->assertFalse($user2->fresh()->hasRole('testRole')); | ||
} | ||
|
||
/** @test */ | ||
public function calling_assignRole_before_saving_object_doesnt_interfere_with_other_objects() | ||
{ | ||
$user = new User(['email' => '[email protected]']); | ||
$user->assignRole('testRole'); | ||
$user->save(); | ||
|
||
$admin_user = new User(['email' => '[email protected]']); | ||
$admin_user->assignRole('testRole2'); | ||
$admin_user->save(); | ||
|
||
$this->assertTrue($admin_user->fresh()->hasRole('testRole2')); | ||
$this->assertFalse($admin_user->fresh()->hasRole('testRole')); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_when_syncing_a_role_from_another_guard() | ||
{ | ||
|