Skip to content

Commit

Permalink
Merge pull request #59 from joydeep-bhowmik/main
Browse files Browse the repository at this point in the history
Fixed one migration problem and  null level handling in getLevel() & getPoints(),  causing some error
  • Loading branch information
cjmellor authored Mar 1, 2024
2 parents 3b9afe0 + 66869aa commit 8887e95
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
39 changes: 38 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
# Ugrade Guide
# Upgrade Guide

## v1.2.2 -> v1.2.3

#### New Migration for Nullable `ended_at` Column

In version `v1.2.3`, a new migration is introduced to make the `ended_at` column in the `streak_histories` table nullable. This change allows flexibility in recording the end time of streaks.

To apply this migration:

1. Locate the migration file responsible for creating the `streak_histories` table. This file should be named something like `YYYY_MM_DD_HHMMSS_create_streak_histories_table.php`.

2. Open the migration file and add the following code inside the `up` method:

```php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('streak_histories', function (Blueprint $table) {
$table->timestamp('ended_at')->nullable()->change();
});
}

public function down(): void
{
Schema::table('streak_histories', function (Blueprint $table) {
$table->dropColumn('ended_at');
});
}
};
```

## v0.0.6 -> v0.0.7

Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_streak_histories_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return new class extends Migration
$table->foreignIdFor(model: Activity::class)->constrained(table: 'streak_activities');
$table->integer(column: 'count')->default(value: 1);
$table->timestamp(column: 'started_at');
$table->timestamp(column: 'ended_at');
$table->timestamp(column: 'ended_at')->nullable();
$table->timestamps();
});
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Concerns/GiveExperienceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,15 @@

Event::assertDispatched(event: UserLevelledUp::class);
});

it('returns 0 when level is not set', function (): void {
$this->user->experience = null;

expect($this->user->getLevel())->toBe(0);
});

it('returns 0 when experience points are not set', function (): void {
$this->user->experience = null;

expect($this->user->getPoints())->toBe(0);
});
1 change: 0 additions & 1 deletion tests/Concerns/HasStreaksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use LevelUp\Experience\Events\StreakStarted;
use LevelUp\Experience\Events\StreakUnfroze;
use LevelUp\Experience\Models\Activity;

use function Pest\Laravel\travel;

uses()->group('streaks');
Expand Down

0 comments on commit 8887e95

Please sign in to comment.