Fixed bug causing child objects of child pages to not be copied

This commit is contained in:
Karl Hobley 2014-06-26 13:55:25 +01:00
parent b9993a8c1e
commit 74d1555ac1
2 changed files with 17 additions and 1 deletions

View file

@ -587,7 +587,7 @@ class Page(MP_Node, ClusterableModel, Indexed):
# Copy child pages
if recursive:
for child_page in self.get_children():
child_page.copy(recursive=True, to=page_copy)
child_page.specific.copy(recursive=True, to=page_copy)
return page_copy

View file

@ -274,3 +274,19 @@ class TestCopyPage(TestCase):
# Check that the url path was updated
self.assertEqual(new_christmas_event.url_path, '/home/new-events-index/christmas/')
def test_copy_page_copies_recursively_with_child_objects(self):
events_index = EventIndex.objects.get(url_path='/home/events/')
# Copy it
new_events_index = events_index.copy(recursive=True, title="New events index", slug='new-events-index')
# Get christmas event
old_christmas_event = events_index.get_children().filter(slug='christmas').first()
new_christmas_event = new_events_index.get_children().filter(slug='christmas').first()
# Check that the speakers were copied
self.assertEqual(new_christmas_event.specific.speakers.count(), 1, "Child objects weren't copied")
# Check that the speakers weren't removed from old page
self.assertEqual(old_christmas_event.specific.speakers.count(), 1, "Child objects were removed from the original page")