@@ -181,17 +181,68 @@ def test_fetch_reified_items_without_readonly
181181 assert children_hash . values . all? ( &:readonly? )
182182 end
183183
184+ def test_fetch_reified_items_with_base_class
185+ post = Post . create! ( a : 1 , b : 2 )
186+
187+ comment_content = 'Example comment'
188+ post . comments . create! ( content : comment_content )
189+
190+ note_body = 'Example note'
191+ post . notes . create! ( body : note_body )
192+
193+ post . create_snapshot! ( identifier : 'v1' )
194+ snapshot = post . snapshots . first
195+
196+ reified_post , reified_children = snapshot . fetch_reified_items
197+
198+ assert_equal post , reified_post
199+ assert reified_post . readonly?
200+ assert_equal [ 'comments' , 'notes' ] , reified_children . keys . sort
201+ assert_equal comment_content , reified_children [ 'comments' ] . first . content
202+ assert_equal note_body , reified_children [ 'notes' ] . first . body
203+ end
204+
184205 def test_fetch_reified_items_with_sti_class
206+ # Inherits snapshot children definition from base class
185207 post = SubPost . create! ( a : 1 , b : 2 )
208+
186209 comment_content = 'Example comment'
187210 post . comments . create! ( content : comment_content )
211+
212+ note_body = 'Example note'
213+ post . notes . create! ( body : note_body )
214+
188215 post . create_snapshot! ( identifier : 'v1' )
189216 snapshot = post . snapshots . first
190- reified_items = snapshot . fetch_reified_items
191217
192- assert_equal post , reified_items . first
193- assert reified_items . first . readonly?
194- assert_equal comment_content , reified_items . second [ :comments ] . first . content
218+ reified_post , reified_children = snapshot . fetch_reified_items
219+
220+ assert_equal post , reified_post
221+ assert reified_post . readonly?
222+ assert_equal [ 'comments' , 'notes' ] , reified_children . keys . sort
223+ assert_equal comment_content , reified_children [ 'comments' ] . first . content
224+ assert_equal note_body , reified_children [ 'notes' ] . first . body
225+ end
226+
227+ def test_fetch_reified_items_with_sti_class_having_own_definition
228+ # Includes "comments" children, but no "notes"
229+ post = SubPostWithOwnDefinition . create! ( a : 1 , b : 2 )
230+
231+ comment_content = 'Example comment'
232+ post . comments . create! ( content : comment_content )
233+
234+ note_body = 'Example note'
235+ post . notes . create! ( body : note_body )
236+
237+ post . create_snapshot! ( identifier : 'v1' )
238+ snapshot = post . snapshots . first
239+
240+ reified_post , reified_children = snapshot . fetch_reified_items
241+
242+ assert_equal post , reified_post
243+ assert reified_post . readonly?
244+ assert_equal [ 'comments' ] , reified_children . keys
245+ assert_equal comment_content , reified_children [ 'comments' ] . first . content
195246 end
196247
197248 def test_fetch_reified_items_handles_dropped_columns!
0 commit comments