mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
fix(#131): invalidate cache when updating recipe markup
This commit is contained in:
parent
e6d66af298
commit
a5cb38421e
2 changed files with 31 additions and 0 deletions
|
|
@ -55,6 +55,13 @@ class Plugin extends Model
|
|||
$model->uuid = Str::uuid();
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function ($model): void {
|
||||
// Reset image cache when markup changes
|
||||
if ($model->isDirty('render_markup')) {
|
||||
$model->current_image = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
|
|
|||
|
|
@ -324,6 +324,30 @@ it('resetIfNotCacheable preserves image for standard devices', function (): void
|
|||
expect($plugin->current_image)->toBe('test-uuid');
|
||||
});
|
||||
|
||||
it('cache is reset when plugin markup changes', function (): void {
|
||||
// Create a plugin with cached image
|
||||
$plugin = App\Models\Plugin::factory()->create([
|
||||
'current_image' => 'cached-uuid',
|
||||
'render_markup' => '<div>Original markup</div>',
|
||||
]);
|
||||
|
||||
// Create devices with standard dimensions (cacheable)
|
||||
Device::factory()->count(2)->create([
|
||||
'width' => 800,
|
||||
'height' => 480,
|
||||
'rotate' => 0,
|
||||
]);
|
||||
|
||||
// Update the plugin markup
|
||||
$plugin->update([
|
||||
'render_markup' => '<div>Updated markup</div>',
|
||||
]);
|
||||
|
||||
// Assert cache was reset when markup changed
|
||||
$plugin->refresh();
|
||||
expect($plugin->current_image)->toBeNull();
|
||||
});
|
||||
|
||||
it('determines correct image format from device model', function (): void {
|
||||
// Test BMP format detection
|
||||
$bmpModel = DeviceModel::factory()->create([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue