diff --git a/app/Models/User.php b/app/Models/User.php index ca7745a99..484a0d166 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -252,6 +252,7 @@ public function purge(): void $this->notifications()->delete(); $this->questionsReceived->each->delete(); + $this->questionsSent->each->delete(); $this->delete(); } diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php index 961b3ab17..c41705209 100644 --- a/tests/Unit/Models/UserTest.php +++ b/tests/Unit/Models/UserTest.php @@ -179,7 +179,7 @@ }); test('purge questions, comments and decendants with user', function () { - $user = User::factory()->create(); + $user = User::factory()->hasQuestionsSent(2)->create(); Question::factory() ->hasChildren(2) ->hasDescendants(2) @@ -188,7 +188,7 @@ 'to_id' => $user->id, ]); - $this->assertDatabaseCount('questions', 5); + $this->assertDatabaseCount('questions', 7); $this->actingAs($user) ->delete(route('profile.destroy'), [