Feature test: After calling an endpoint with json(MEHTOD, URL) that sets an ability, user->can doesn't work
robertoperez-digital opened this issue · 1 comments
Hi! I'm facing a weird issue
In my feature test I call this
$this->actingAs($user)
->json('POST', "URL that creates an object", $data);
In the controller function I do
$object = Object::create([data]);
Bouncer::allow($user)->to('ability', $object);
After the call I check in my test if
$user->can('ability', $object);
It doesn't return true, I printed the result and is not true, nor false, is like empty??
Additional info:
I have a custom Ability class registered in AppServiceProvider
Bouncer::useAbilityModel(Ability::class);
Funny thing, If I call that endpoint from an external tool like postman, everything is working as expected, it is just acting weird in the tests.
Can you give some light on this?
Any info you can give will be very appreciated.
Thank you.
Sorry to bother, I found my problem. It was the Bouncer cache trolling me, after the call I tested using
Bouncer::refresh();
And
$user->can('ability', $object);
Returned true as expected
I disabled cache for the whole test