@@ -31,11 +31,20 @@ protected function setUp(): void
3131 */
3232 public function versions_can_be_created ()
3333 {
34- $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' ]);
34+ $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' , ' extends ' => [ ' foo ' => ' bar ' ] ]);
3535
3636 $ this ->assertCount (1 , $ post ->versions );
3737 $ this ->assertDatabaseCount ('versions ' , 1 );
3838
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+
3948 // version2
4049 $ post ->update (['title ' => 'version2 ' ]);
4150 $ post ->refresh ();
@@ -119,29 +128,35 @@ public function it_can_create_version_with_snapshot_strategy()
119128 public function it_can_revert_to_target_version ()
120129 {
121130 $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' ]);
122- $ post ->update (['title ' => 'version2 ' , 'extends ' => ['foo ' => 'bar ' ]]);
131+ $ post ->update (['title ' => 'version2 ' , 'extends ' => ['foo2 ' => 'bar2 ' ]]);
123132 $ post ->update (['title ' => 'version3 ' , 'content ' => 'version3 content ' , 'extends ' => ['name ' => 'overtrue ' ]]);
124133 $ post ->update (['title ' => 'version4 ' , 'content ' => 'version4 content ' ]);
125134
126135 // #29
127- $ version = $ post ->firstVersion ;
128- $ post = $ version ->revertWithoutSaving ();
136+ $ version1 = $ post ->firstVersion ;
137+ $ post = $ version1 ->revertWithoutSaving ();
129138
130139 $ this ->assertSame ('version1 ' , $ post ->title );
131140 $ this ->assertSame ('version1 content ' , $ post ->content );
132141 $ this ->assertNull ($ post ->extends );
133142
134143 $ post ->refresh ();
135144
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+
136152 // revert version 2
137153 $ post ->revertToVersion ($ post ->firstVersion ->nextVersion ()->id );
138154 $ post ->refresh ();
139155
140156 // only title updated
141157 $ this ->assertSame ('version2 ' , $ post ->title );
142158 $ this ->assertSame ('version4 content ' , $ post ->content );
143-
144- $ this ->assertSame (['foo ' => 'bar ' ], $ post ->extends );
159+ $ this ->assertSame (['foo2 ' => 'bar2 ' ], $ post ->extends );
145160
146161 // revert version 3
147162 $ post ->revertToVersion (3 );
0 commit comments