# HG changeset patch # User Marcin Kuzminski # Date 2011-11-26 22:40:41 # Node ID ac54aa4200e8e7e72a6053269dbeed06eb314a01 # Parent 8321b3d19b1f5b69716619679c276131172b1989 fixed bug with eager deletes in notifications - added relevant tests for that diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1227,8 +1227,7 @@ class UserNotification(Base, BaseModel): user = relationship('User', lazy="joined") notification = relationship('Notification', lazy="joined", - order_by=lambda:Notification.created_on.desc(), - cascade='all') + order_by=lambda:Notification.created_on.desc(),) def mark_as_read(self): self.read = True diff --git a/rhodecode/tests/test_models.py b/rhodecode/tests/test_models.py --- a/rhodecode/tests/test_models.py +++ b/rhodecode/tests/test_models.py @@ -267,6 +267,7 @@ class TestNotifications(unittest.TestCas self.assertEqual(un, []) self._clean_notifications() + def test_delete_association(self): self.assertEqual([], Notification.query().all()) @@ -289,13 +290,31 @@ class TestNotifications(unittest.TestCas notification.notification_id) Session().commit() - unotification = UserNotification.query()\ + u3notification = UserNotification.query()\ .filter(UserNotification.notification == notification)\ .filter(UserNotification.user_id == self.u3)\ .scalar() - self.assertEqual(unotification, None) + self.assertEqual(u3notification, None) + + # notification object is still there + self.assertEqual(Notification.query().all(), [notification]) + + #u1 and u2 still have assignments + u1notification = UserNotification.query()\ + .filter(UserNotification.notification == + notification)\ + .filter(UserNotification.user_id == self.u1)\ + .scalar() + self.assertNotEqual(u1notification, None) + u2notification = UserNotification.query()\ + .filter(UserNotification.notification == + notification)\ + .filter(UserNotification.user_id == self.u2)\ + .scalar() + self.assertNotEqual(u2notification, None) + self._clean_notifications() def test_notification_counter(self):