damned-lies r1388 - in trunk: . vertimus vertimus/tests



Author: stephaner
Date: Sat Jan 24 22:18:11 2009
New Revision: 1388
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1388&view=rev

Log:
2009-01-24  StÃphane Raimbault  <stephane raimbault gmail com>

	* vertimus/models.py: Fixes bug #568777
	* vertimus/tests/__init__.py: Added unit tests for this bug.


Modified:
   trunk/ChangeLog
   trunk/vertimus/models.py
   trunk/vertimus/tests/__init__.py

Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py	(original)
+++ trunk/vertimus/models.py	Sat Jan 24 22:18:11 2009
@@ -661,11 +661,19 @@
         self.save_action_db(state, person, comment, file)
 
         try:
-            # Exclude himself
-            action_db = ActionDb.objects.filter(state_db__id=state._state_db.id).exclude(
-                name__in=['WC', 'UNDO']).order_by('-id')[1]
-            action = action_db.get_action()
-            return action._new_state()
+            # Exclude WC because this action is a noop on State
+            actions_db = ActionDb.objects.filter(state_db__id=state._state_db.id).exclude(
+                name='WC').order_by('-id')
+            i = 0
+            while (i < len(actions_db)):
+                if actions_db[i].name == 'UNDO':
+                    # Skip Undo and the associated action
+                    i = i + 2
+                else:
+                    # Found
+                    action = actions_db[i].get_action()
+                    return action._new_state()
+            return StateNone()
         except:
             return StateNone()
 

Modified: trunk/vertimus/tests/__init__.py
==============================================================================
--- trunk/vertimus/tests/__init__.py	(original)
+++ trunk/vertimus/tests/__init__.py	Sat Jan 24 22:18:11 2009
@@ -392,7 +392,7 @@
         state.save()
 
         self.assertEqual(state.name, 'None')
-
+        
         action = ActionAbstract.new_by_name('RT')
         state = state.apply_action(action, self.pt, "Translating")
         state.save()
@@ -410,6 +410,24 @@
         state.save()
 
         self.assertEqual(state.name, 'Translated')
+            
+        action = ActionAbstract.new_by_name('RT')
+        state = state.apply_action(action, self.pt, "Translating 1")
+        state.save()
+        
+        action = ActionAbstract.new_by_name('UNDO')
+        state = state.apply_action(action, self.pt, "Undo 1")
+        state.save()
+        
+        action = ActionAbstract.new_by_name('RT')
+        state = state.apply_action(action, self.pt, "Translating 2")
+        state.save()
+        
+        action = ActionAbstract.new_by_name('UNDO')
+        state = state.apply_action(action, self.pt, "Undo 2")
+        state.save()
+        
+        self.assertEqual(state.name, 'Translated')
         
     def test_uploaded_file_validation(self):
         # Test a non valid po file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]