Skip to content

Commit be139fc

Browse files
committed
add activity log test
1 parent 7035eb2 commit be139fc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

stubs/modules/User/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Illuminate\Foundation\Auth\User as Authenticatable;
1111
use Illuminate\Notifications\Notifiable;
1212
use Modules\AdminAuth\Notifications\ResetPassword;
13-
// use Modules\Traits\ActivityLog;
13+
// use Modules\Support\Traits\ActivityLog;
1414
use Modules\Support\Traits\Searchable;
1515
use Spatie\Permission\Traits\HasRoles;
1616

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Modules\Support\Traits\ActivityLog;
7+
8+
uses(ActivityLog::class);
9+
10+
beforeEach(function () {
11+
Schema::create('items', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('name')->nullable();
14+
$table->timestamps();
15+
});
16+
});
17+
18+
it('logs the activity for the model', function () {
19+
$model = new class extends Model
20+
{
21+
use ActivityLog;
22+
23+
protected $table = 'items';
24+
25+
protected $guarded = [];
26+
};
27+
28+
$item1 = $model->create(['name' => 'Item 1']);
29+
30+
$item1->delete();
31+
32+
$this->assertDatabaseHas('activity_log', [
33+
'subject_id' => $item1->id,
34+
'subject_type' => get_class($item1),
35+
'description' => 'deleted',
36+
]);
37+
});

0 commit comments

Comments
 (0)