Commits

Odd Simon Simonsen committed 5dff2d4

CustomFieldAdminPlugin: When creating/deleting/updating/reordering the customfield cache needed to be cleared.

  • Participants
  • Parent commits f3213bf

Comments (0)

Files changed (2)

0.11/customfieldadmin/api.py

         if order == "":
             order = len(self.get_custom_fields())
         self.config.set('ticket-custom', cfield['name'] + '.order', order)
-        self.config.save()
+        self._save()
 
     def update_custom_field(self, cfield, create=False):
         """ Updates a custom. Option to 'create' is kept in order to keep
                 self.config.remove('ticket-custom', option)
         # Persist permanent deletes
         if not modify:
-            self.config.save()
+            self._save()
+
+    def _save(self):
+        # Saves a value, clear caches if needed / supported
+        self.config.save()
+        try:
+            # cache support for Trac >= 0.12
+            del TicketSystem(self.env).custom_fields
+        except AttributeError:
+            # 0.11 cached values internally
+            TicketSystem(self.env)._custom_fields = None

0.11/customfieldadmin/tests/api.py

                 __import__('customfieldadmin', ['__version__']).__version__) \
                     in self.env.systeminfo)
 
+    def test_create(self):
+        for f in ['one', 'two', 'three']:
+            cfield = {'name': f, 'type': 'text', 'label': f.capitalize()}
+            self.cf_api.create_custom_field(cfield)
+        self.assertEquals(self.cf_api.get_custom_fields(),
+                    [{'name': u'one', 'format': 'plain', 'value': '',
+                      'label': u'One', 'type': u'text', 'order': 1},
+                     {'name': u'two', 'format': 'plain', 'value': '',
+                      'label': u'Two', 'type': u'text', 'order': 2},
+                     {'name': u'three', 'format': 'plain', 'value': '',
+                      'label': u'Three', 'type': u'text', 'order': 3}])
+
     def test_delete_unknown_options(self):
         cf = customfield = {'name': 'foo', 'type': 'text', 'label': 'Foo'}
         self.cf_api.create_custom_field(cf)