Skip to content

Commit

Permalink
delete executions when deleting a script
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedvaziry committed Jun 8, 2024
1 parent 849d814 commit c9c2185
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/Models/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class Script extends AbstractModel
'content',
];

public static function boot(): void
{
parent::boot();

static::deleting(function (Script $script) {
$script->executions()->delete();
});
}

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/ScriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public function test_delete_script(): void
'user_id' => $this->user->id,
]);

$scriptExecution = ScriptExecution::factory()->create([
'script_id' => $script->id,
'status' => ScriptExecutionStatus::EXECUTING,
]);

$this->delete(
route('scripts.delete', [
'script' => $script,
Expand All @@ -87,6 +92,10 @@ public function test_delete_script(): void
$this->assertDatabaseMissing('scripts', [
'id' => $script->id,
]);

$this->assertDatabaseMissing('script_executions', [
'id' => $scriptExecution->id,
]);
}

public function test_execute_script_and_view_log(): void
Expand Down

0 comments on commit c9c2185

Please sign in to comment.