Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ public function scopeMostSolutions(Builder $query, int $inLastDays = null)
{
return $query->withCount(['replyAble as solutions_count' => function ($query) use ($inLastDays) {
$query->where('replyable_type', 'threads')
->join('threads', 'threads.solution_reply_id', '=', 'replies.id');
->join('threads', function ($join) {
$join->on('threads.solution_reply_id', '=', 'replies.id')
->on('threads.author_id', '!=', 'replies.author_id');
});

if ($inLastDays) {
$query->where('replies.created_at', '>', now()->subDays($inLastDays));
Expand Down
2 changes: 1 addition & 1 deletion resources/views/forum/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
</ul>

<p class="px-5 pt-3 pb-5 text-center text-xs text-gray-700">
Solutions given in the past year.
Solutions given in the past year. Excluding solutions from thread authors.
</p>
</div>

Expand Down
19 changes: 19 additions & 0 deletions tests/Integration/Models/UserTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Jobs\MarkThreadSolution;
use App\Models\Article;
use App\Models\Reply;
use App\Models\Thread;
Expand Down Expand Up @@ -56,6 +57,24 @@
expect($user->countArticles())->toBe(1);
});

it('excludes author solutions from mostSolutions count', function () {
$user = $this->login();
$thread = Thread::factory()->create([
'author_id' => $user->id(),
]);
$reply = Reply::factory()->create([
'author_id' => $user->id(),
]);

$this->dispatch(new MarkThreadSolution($thread, $reply, $user));
expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(0);

$otherThread = Thread::factory()->create();

$this->dispatch(new MarkThreadSolution($otherThread, $reply, $user));
expect($user->mostSolutions()->find($user->id())->solutions_count)->toBe(1);
});

// Helpers
function createTwoSolutionReplies(User $user)
{
Expand Down