Skip to content

Commit

Permalink
Model::preventsLazyLoading() check added
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jan 31, 2025
1 parent 8d45011 commit c0602d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/HasPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Permission\Tests;

use Illuminate\Database\Eloquent\Model;
use DB;
use Spatie\Permission\Contracts\Permission;
use Spatie\Permission\Contracts\Role;
Expand Down Expand Up @@ -769,6 +770,8 @@ public function it_can_reject_permission_based_on_logged_in_user_guard()
/** @test */
public function it_can_be_given_a_permission_on_role_when_lazy_loading_is_restricted()
{
$this->assertTrue(Model::preventsLazyLoading());

try {
$testRole = app(Role::class)->with('permissions')->get()->first();

Expand All @@ -783,6 +786,8 @@ public function it_can_be_given_a_permission_on_role_when_lazy_loading_is_restri
/** @test */
public function it_can_be_given_a_permission_on_user_when_lazy_loading_is_restricted()
{
$this->assertTrue(Model::preventsLazyLoading());

try {
User::create(['email' => '[email protected]']);
$testUser = User::with('permissions')->get()->first();
Expand Down
5 changes: 5 additions & 0 deletions tests/HasRolesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Permission\Tests;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Contracts\Permission;
use Spatie\Permission\Contracts\Role;
Expand Down Expand Up @@ -861,6 +862,8 @@ public function it_does_not_detach_roles_when_user_soft_deleting()
/** @test */
public function it_can_be_given_a_role_on_permission_when_lazy_loading_is_restricted()
{
$this->assertTrue(Model::preventsLazyLoading());

try {
$testPermission = app(Permission::class)->with('roles')->get()->first();

Expand All @@ -875,6 +878,8 @@ public function it_can_be_given_a_role_on_permission_when_lazy_loading_is_restri
/** @test */
public function it_can_be_given_a_role_on_user_when_lazy_loading_is_restricted()
{
$this->assertTrue(Model::preventsLazyLoading());

try {
User::create(['email' => '[email protected]']);
$user = User::with('roles')->get()->first();
Expand Down

0 comments on commit c0602d8

Please sign in to comment.