@@ -31,11 +31,20 @@ protected function setUp(): void
31
31
*/
32
32
public function versions_can_be_created ()
33
33
{
34
- $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' ]);
34
+ $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' , ' extends ' => [ ' foo ' => ' bar ' ] ]);
35
35
36
36
$ this ->assertCount (1 , $ post ->versions );
37
37
$ this ->assertDatabaseCount ('versions ' , 1 );
38
38
39
+ $ version = $ post ->lastVersion ;
40
+
41
+ $ this ->assertSame ($ post ->title , $ version ->contents ['title ' ]);
42
+ $ this ->assertSame ($ post ->content , $ version ->contents ['content ' ]);
43
+
44
+ // json cast
45
+ $ this ->assertIsString ($ version ->contents ['extends ' ]);
46
+ $ this ->assertSame ($ post ->getRawOriginal ('extends ' ), $ version ->contents ['extends ' ]);
47
+
39
48
// version2
40
49
$ post ->update (['title ' => 'version2 ' ]);
41
50
$ post ->refresh ();
@@ -119,29 +128,35 @@ public function it_can_create_version_with_snapshot_strategy()
119
128
public function it_can_revert_to_target_version ()
120
129
{
121
130
$ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' ]);
122
- $ post ->update (['title ' => 'version2 ' , 'extends ' => ['foo ' => 'bar ' ]]);
131
+ $ post ->update (['title ' => 'version2 ' , 'extends ' => ['foo2 ' => 'bar2 ' ]]);
123
132
$ post ->update (['title ' => 'version3 ' , 'content ' => 'version3 content ' , 'extends ' => ['name ' => 'overtrue ' ]]);
124
133
$ post ->update (['title ' => 'version4 ' , 'content ' => 'version4 content ' ]);
125
134
126
135
// #29
127
- $ version = $ post ->firstVersion ;
128
- $ post = $ version ->revertWithoutSaving ();
136
+ $ version1 = $ post ->firstVersion ;
137
+ $ post = $ version1 ->revertWithoutSaving ();
129
138
130
139
$ this ->assertSame ('version1 ' , $ post ->title );
131
140
$ this ->assertSame ('version1 content ' , $ post ->content );
132
141
$ this ->assertNull ($ post ->extends );
133
142
134
143
$ post ->refresh ();
135
144
145
+
146
+ $ version2 = $ post ->firstVersion ->nextVersion ();
147
+ $ this ->assertSame ('version2 ' , $ version2 ->contents ['title ' ]);
148
+ // only title updated
149
+ $ this ->assertNull ($ version2 ->contents ['content ' ] ?? null );
150
+ $ this ->assertSame (json_encode (['foo2 ' => 'bar2 ' ]), $ version2 ->contents ['extends ' ]);
151
+
136
152
// revert version 2
137
153
$ post ->revertToVersion ($ post ->firstVersion ->nextVersion ()->id );
138
154
$ post ->refresh ();
139
155
140
156
// only title updated
141
157
$ this ->assertSame ('version2 ' , $ post ->title );
142
158
$ this ->assertSame ('version4 content ' , $ post ->content );
143
-
144
- $ this ->assertSame (['foo ' => 'bar ' ], $ post ->extends );
159
+ $ this ->assertSame (['foo2 ' => 'bar2 ' ], $ post ->extends );
145
160
146
161
// revert version 3
147
162
$ post ->revertToVersion (3 );
0 commit comments