Skip to content

Commit

Permalink
Refactor User model purge method to delete associated questions sent …
Browse files Browse the repository at this point in the history
…by the user
  • Loading branch information
MrPunyapal committed Sep 20, 2024
1 parent 28b76c5 commit 2c67a73
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public function purge(): void
$this->notifications()->delete();

$this->questionsReceived->each->delete();
$this->questionsSent->each->delete();

$this->delete();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -188,7 +188,7 @@
'to_id' => $user->id,
]);

$this->assertDatabaseCount('questions', 5);
$this->assertDatabaseCount('questions', 7);

$this->actingAs($user)
->delete(route('profile.destroy'), [
Expand Down

0 comments on commit 2c67a73

Please sign in to comment.