Skip to content

Commit

Permalink
Merge branch 'master' of github.com:spatie/nova-backup-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Feb 27, 2019
2 parents 3ea1a91 + 960becf commit afe1ebf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Http/Controllers/BackupStatusesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BackupStatusesController extends ApiController
{
public function index()
{
return Cache::remember('backup-statuses', 1 / 15, function () {
return Cache::remember('backup-statuses', now()->addMinutes(1 / 15), function () {
return BackupDestinationStatusFactory::createForMonitorConfig(config('backup.monitor_backups'))
->map(function (BackupDestinationStatus $backupDestinationStatus) {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/BackupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function index(Request $request)

$backupDestination = BackupDestination::create($validated['disk'], config('backup.backup.name'));

return Cache::remember("backups-{$validated['disk']}", 1 / 15, function () use ($backupDestination) {
return Cache::remember("backups-{$validated['disk']}", now()->addMinutes(1 / 15), function () use ($backupDestination) {
return $backupDestination
->backups()
->map(function (Backup $backup) {
Expand Down
16 changes: 16 additions & 0 deletions tests/Controllers/BackupStatusesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Spatie\BackupTool\Tests;

use Closure;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;

class BackupStatusesControllerTest extends TestCase
{
/** @test */
Expand All @@ -20,4 +24,16 @@ public function it_can_get_all_backup_statuses()
],
]);
}

/** @test */
public function it_caches_the_index_of_a_disk()
{
Cache::shouldReceive('remember')
->with('backup-statuses', Carbon::class, Closure::class)
->once();

$this
->getJson('/nova-vendor/spatie/backup-tool/backup-statuses')
->assertSuccessful();
}
}
16 changes: 16 additions & 0 deletions tests/Controllers/BackupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Spatie\BackupTool\Tests;

use Closure;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
use Spatie\BackupTool\Jobs\CreateBackupJob;
Expand Down Expand Up @@ -84,4 +86,18 @@ public function it_wont_delete_backups_for_an_invalid_disk_name()
'disk',
]);
}

/** @test */
public function it_caches_the_index_of_a_disk()
{
$disk = 'local';

Cache::shouldReceive('remember')
->with('backups-'.$disk, Carbon::class, Closure::class)
->once();

$this
->getJson('/nova-vendor/spatie/backup-tool/backups?disk='.$disk)
->assertSuccessful();
}
}

0 comments on commit afe1ebf

Please sign in to comment.