|
2 | 2 |
|
3 | 3 | use Oddvalue\LaravelDrafts\Tests\Post;
|
4 | 4 | use Oddvalue\LaravelDrafts\Tests\SoftDeletingPost;
|
| 5 | +use function Spatie\PestPluginTestTime\testTime; |
5 | 6 |
|
6 | 7 | it('keeps the correct number of revisions', function () {
|
7 | 8 | config(['drafts.revisions.keep' => 3]);
|
|
14 | 15 | }
|
15 | 16 | };
|
16 | 17 |
|
17 |
| - config(['drafts.revisions.keep' => 3]); |
18 | 18 | $post = Post::factory()->create(['title' => 'Rev 1']);
|
19 | 19 | $revsExist('Rev 1');
|
20 | 20 | $this->travel(1)->minutes();
|
|
39 | 39 | ]);
|
40 | 40 | });
|
41 | 41 |
|
| 42 | +it('sets the correct timestamps on revisions', function () { |
| 43 | + $recordsExist = function (...$records) { |
| 44 | + foreach ($records as $record) { |
| 45 | + $this->assertDatabaseHas('posts', $record); |
| 46 | + } |
| 47 | + }; |
| 48 | + |
| 49 | + testTime()->freeze('2021-01-02 14:00:00'); |
| 50 | + |
| 51 | + $post = Post::factory()->create(['title' => 'Rev 1']); |
| 52 | + $recordsExist(['title' => 'Rev 1', 'updated_at' => '2021-01-02 14:00:00']); |
| 53 | + |
| 54 | + testTime()->addMinute(); |
| 55 | + $post->fresh()->update(['title' => 'Rev 2']); |
| 56 | + |
| 57 | + $recordsExist( |
| 58 | + ['title' => 'Rev 1', 'updated_at' => '2021-01-02 14:00:00'], |
| 59 | + ['title' => 'Rev 2', 'updated_at' => '2021-01-02 14:01:00'], |
| 60 | + ); |
| 61 | + |
| 62 | + testTime()->addMinute(); |
| 63 | + $post->fresh()->update(['title' => 'Rev 3']); |
| 64 | + |
| 65 | + $recordsExist( |
| 66 | + ['title' => 'Rev 1', 'updated_at' => '2021-01-02 14:00:00'], |
| 67 | + ['title' => 'Rev 2', 'updated_at' => '2021-01-02 14:01:00'], |
| 68 | + ['title' => 'Rev 3', 'updated_at' => '2021-01-02 14:02:00'], |
| 69 | + ); |
| 70 | + |
| 71 | + testTime()->addMinute(); |
| 72 | + $post->fresh()->update(['title' => 'Rev 4']); |
| 73 | + |
| 74 | + $recordsExist( |
| 75 | + ['title' => 'Rev 1', 'updated_at' => '2021-01-02 14:00:00'], |
| 76 | + ['title' => 'Rev 2', 'updated_at' => '2021-01-02 14:01:00'], |
| 77 | + ['title' => 'Rev 3', 'updated_at' => '2021-01-02 14:02:00'], |
| 78 | + ['title' => 'Rev 4', 'updated_at' => '2021-01-02 14:03:00'], |
| 79 | + ); |
| 80 | +}); |
| 81 | + |
42 | 82 | it('can disable revisions', function () {
|
43 | 83 | config(['drafts.revisions.keep' => 0]);
|
44 | 84 | $post = Post::factory()->create(['title' => 'Foo']);
|
|
0 commit comments