changeset 1733:ac54aa4200e8 beta

fixed bug with eager deletes in notifications - added relevant tests for that
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Nov 2011 23:40:41 +0200
parents 8321b3d19b1f
children 48d4fcf04a29
files rhodecode/model/db.py rhodecode/tests/test_models.py
diffstat 2 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/model/db.py	Sat Nov 26 21:50:08 2011 +0200
+++ b/rhodecode/model/db.py	Sat Nov 26 23:40:41 2011 +0200
@@ -1227,8 +1227,7 @@
 
     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
--- a/rhodecode/tests/test_models.py	Sat Nov 26 21:50:08 2011 +0200
+++ b/rhodecode/tests/test_models.py	Sat Nov 26 23:40:41 2011 +0200
@@ -267,6 +267,7 @@
         self.assertEqual(un, [])
 
         self._clean_notifications()
+
     def test_delete_association(self):
 
         self.assertEqual([], Notification.query().all())
@@ -289,13 +290,31 @@
                                    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):