Browse Source

WIP #410: fail on thread merge with itself

Rafał Pitoń 10 years ago
parent
commit
236c341cd7
2 changed files with 6 additions and 0 deletions
  1. 3 0
      misago/threads/models/thread.py
  2. 3 0
      misago/threads/tests/test_thread_model.py

+ 3 - 0
misago/threads/models/thread.py

@@ -64,6 +64,9 @@ class Thread(models.Model):
         super(Thread, self).delete(*args, **kwargs)
 
     def merge(self, other_thread):
+        if self.pk == other_thread.pk:
+            raise ValueError("thread can't be merged with itself")
+
         from misago.threads.signals import merge_thread
         merge_thread.send(sender=self, other_thread=other_thread)
 

+ 3 - 0
misago/threads/tests/test_thread_model.py

@@ -222,6 +222,9 @@ class ThreadModelTests(TestCase):
 
     def test_merge(self):
         """merge(other_thread) moves other thread content to this thread"""
+        with self.assertRaises(ValueError):
+            self.thread.merge(self.thread)
+
         datetime = timezone.now() + timedelta(5)
 
         other_thread = Thread(