Commits

cmlenz  committed 65c89d2

Fix an issue with the reordering commands introduced in [2414] with newer versions of SQLite.

  • Participants
  • Parent commits 3220b17
  • Branches trunk

Comments (0)

Files changed (3)

File trac/scripts/admin.py

         env = self.env_open()
         enum_cls = self._enum_map[type]
         enum1 = enum_cls(env, name)
-        enum1.value = int(enum1.value) + direction
+        enum1.value = int(float(enum1.value) + direction)
         for enum2 in enum_cls.select(env):
-            if int(enum2.value) == int(enum1.value):
-                enum2.value = int(enum2.value) - direction
+            if int(float(enum2.value)) == enum1.value:
+                enum2.value = int(float(enum2.value) - direction)
                 break
         else:
             return

File trac/ticket/model.py

         self.env.log.info('Deleting %s %s' % (self.type, self.name))
         cursor.execute("DELETE FROM enum WHERE type=%s AND value=%s",
                        (self.type, self._old_value))
-        self.value = self._old_value = None
-        self.name = None
 
         if handle_ta:
             db.commit()
+        self.value = self._old_value = None
+        self.name = self._old_name = None
 
     def insert(self, db=None):
         assert not self.exists, 'Cannot insert existing %s' % self.type
 
         cursor = db.cursor()
         self.env.log.debug("Creating new %s '%s'" % (self.type, self.name))
-        value = self.value
-        if not value:
+        if not self.value:
             cursor.execute(("SELECT COALESCE(MAX(%s),0) FROM enum "
                             "WHERE type=%%s") % db.cast('value', 'int'),
                            (self.type,))
-            value = str(int(cursor.fetchone()[0]) + 1)
+            self.value = int(float(cursor.fetchone()[0])) + 1
         cursor.execute("INSERT INTO enum (type,name,value) VALUES (%s,%s,%s)",
-                       (self.type, self.name, value))
+                       (self.type, self.name, self.value))
 
         if handle_ta:
             db.commit()
+        self._old_name = self.name
+        self._old_value = self.value
 
     def update(self, db=None):
         assert self.exists, 'Cannot update non-existent %s' % self.type
         if self.name != self._old_name:
             # Update tickets
             cursor.execute("UPDATE ticket SET %s=%%s WHERE %s=%%s" %
-                           (self.ticket_col, self.ticket_col), (self.name, self._old_name))
-            self._old_name = self.name
-            self._old_value = self.value
+                           (self.ticket_col, self.ticket_col),
+                           (self.name, self._old_name))
 
         if handle_ta:
             db.commit()
+        self._old_name = self.name
+        self._old_value = self.value
 
     def select(cls, env, db=None):
         if not db:

File trac/ticket/tests/model.py

 from trac.config import Configuration
+from trac.core import TracError
 from trac.ticket.model import Ticket, Component, Milestone, Priority, Type
 from trac.test import EnvironmentStub
 
                 self.fail('Unexpected change (%s)'
                           % ((t, author, field, old, new),))
 
-    def test_abstractenum(self):
-        """
-        Verify basic AbstractEnum functionality.
-        """
-        p = Priority(self.env, 'major')
-        self.assertEqual(p.name, 'major')
-        self.assertEqual(p.value, '3')
-        p = Priority(self.env)
-        p.name = 'foo'
-        p.insert()
-        p = Priority(self.env)
-        p.name = 'bar'
-        p.value = 100
-        p.insert()
-        p = Priority(self.env, 'foo')
-        p.name = 'foo2'
-        p.update()
-        p = Priority(self.env, 'foo2')
-        p.delete()        
-        p = Priority(self.env, 'bar')
-        p.delete()        
 
-    def test_ticket_type_enum(self):
-        """
-        The Type (ticket type) enum class behaves a little different than
-        the rest, so it gets some additional testing.
-        """
-        t = Type(self.env, 'task')
-        self.assertEqual(t.name, 'task')
-        self.assertEqual(t.value, '3')
-        t.name = 'foo'
-        t.update()
+class EnumTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.env = EnvironmentStub(default_data=True)
+
+    def test_priority_fetch(self):
+        prio = Priority(self.env, 'major')
+        self.assertEqual(prio.name, 'major')
+        self.assertEqual(prio.value, '3')
+
+    def test_priority_insert(self):
+        prio = Priority(self.env)
+        prio.name = 'foo'
+        prio.insert()
+        self.assertEqual(True, prio.exists)
+
+    def test_priority_insert_with_value(self):
+        prio = Priority(self.env)
+        prio.name = 'bar'
+        prio.value = 100
+        prio.insert()
+        self.assertEqual(True, prio.exists)
+
+    def test_priority_update(self):
+        prio = Priority(self.env, 'major')
+        prio.name = 'foo'
+        prio.update()
+        Priority(self.env, 'foo')
+        self.assertRaises(TracError, Priority, self.env, 'major')
+
+    def test_priority_delete(self):
+        prio = Priority(self.env, 'major')
+        prio.delete()
+        self.assertEqual(False, prio.exists)
+        self.assertRaises(TracError, Priority, self.env, 'major')
+
+    def test_ticket_type_update(self):
+        tkttype = Type(self.env, 'task')
+        self.assertEqual(tkttype.name, 'task')
+        self.assertEqual(tkttype.value, '3')
+        tkttype.name = 'foo'
+        tkttype.update()
+        Type(self.env, 'foo')
 
 
 class MilestoneTestCase(unittest.TestCase):
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TicketTestCase, 'test'))
+    suite.addTest(unittest.makeSuite(EnumTestCase, 'test'))
     suite.addTest(unittest.makeSuite(MilestoneTestCase, 'test'))
     return suite