'Example of migrating ReferenceField storage'

def test_migrate_references(self):

    class User(Document, ):
        name = StringField()
    class Group(Document, ):
        author = ReferenceField(User, dbref=True)
        members = ListField(ReferenceField(User, dbref=True))
    User.drop_collection()
    Group.drop_collection()
    user = User(name='Ross').save()
    group = Group(author=user, members=[user]).save()
    raw_data = Group._get_collection().find_one()
    self.assertTrue(isinstance(raw_data['author'], DBRef))
    self.assertTrue(isinstance(raw_data['members'][0], DBRef))
    group = Group.objects.first()
    self.assertEqual(group.author, user)
    self.assertEqual(group.members, [user])
    class Group(Document, ):
        author = ReferenceField(User, dbref=False)
        members = ListField(ReferenceField(User, dbref=False))
    for g in Group.objects():
        g._mark_as_changed('author')
        g._mark_as_changed('members')
        g.save()
    group = Group.objects.first()
    self.assertEqual(group.author, user)
    self.assertEqual(group.members, [user])
    raw_data = Group._get_collection().find_one()
    self.assertTrue(isinstance(raw_data['author'], ObjectId))
    self.assertTrue(isinstance(raw_data['members'][0], ObjectId))
