Skip to content

Commit

Permalink
Merge pull request #10404 from nanaya/mp-isnew
Browse files Browse the repository at this point in the history
Remove redundant isNew attribute
  • Loading branch information
notbakaneko authored Jul 28, 2023
2 parents 4f664da + d35b23c commit ecc3d6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public function startPlay(User $user, PlaylistItem $playlistItem)

return $this->getConnection()->transaction(function () use ($user, $playlistItem) {
$agg = UserScoreAggregate::new($user, $this);
if ($agg->isNew) {
if ($agg->wasRecentlyCreated) {
$this->incrementInstance('participant_count');
}

Expand Down
3 changes: 0 additions & 3 deletions app/Models/Multiplayer/UserScoreAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class UserScoreAggregate extends Model
];
protected $table = 'multiplayer_rooms_high';

public $isNew = false;

public static function getPlaylistItemUserHighScore(Score $score)
{
return PlaylistItemUserHighScore::firstOrNew([
Expand Down Expand Up @@ -86,7 +84,6 @@ public static function new(User $user, Room $room): self
$obj = static::lookupOrDefault($user, $room);

if (!$obj->exists) {
$obj->isNew = true;
$obj->save(); // force a save now to avoid being trolled later.
$obj->recalculate();
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Models/Multiplayer/RoomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ public function testRoomHasEnded()
$room->startPlay($user, $playlistItem);
}

public function testStartPlay(): void
{
$user = User::factory()->create();
$room = Room::factory()->create();
$playlistItem = PlaylistItem::factory()->create(['room_id' => $room]);

$this->expectCountChange(fn () => $room->participant_count, 1);
$this->expectCountChange(fn () => $room->userHighScores()->count(), 1);
$this->expectCountChange(fn () => $room->scores()->count(), 1);

$room->startPlay($user, $playlistItem);
$room->refresh();

$this->assertSame($user->getKey(), $room->scores()->last()->user_id);
}

public function testMaxAttemptsReached()
{
$user = User::factory()->create();
Expand Down

0 comments on commit ecc3d6a

Please sign in to comment.