Commits

hacklab committed 1e2fa91

name order is preserved when renaming a multi-named item

  • Participants
  • Parent commits a974190
  • Branches namespaces

Comments (0)

Files changed (2)

MoinMoin/items/__init__.py

         if name is None:
             name = self.name
         oldname = meta.get(NAME)
+
         if oldname:
             if type(oldname) is not types.ListType:
                 oldname = [oldname]
-            if name not in oldname: #this is a rename
+            if name != self.name: #this is a rename
                 meta[NAME_OLD] = oldname[:]
-                try:
+                if name not in oldname:
+                    i = oldname.index(self.name)
+                    oldname[i:i+1] = [name]
+                else:
                     oldname.remove(self.name)
-                except ValueError:
-                    pass
-                oldname.append(name)
                 meta[NAME] = oldname
         else:
             meta[NAME] = [name]

MoinMoin/items/_tests/test_Item.py

         item4 = Item.create(u'Second')
         assert item4.meta[CONTENTTYPE] == 'application/x-nonexistent'
 
+    def test_order_of_names_is_preserved_when_renaming(self):
+        update_item(u'Page',
+                    {NAME: [u'First',
+                            u'Second',
+                            u'Third',
+                            u'Fourth',
+                            u'Fifth',
+                            ],
+                     CONTENTTYPE: u'text/x.moin.wiki'}, u'content')
+
+        item = Item.create(u'Second')
+        item.rename(u'Second renamed', comment=u'renamed')
+
+        assert item.meta[NAME] == [u'First', 'Second renamed', 'Third', 'Fourth', 'Fifth']
+
+        item = Item.create(u'Second renamed')
+        item.rename(u'Fourth', comment=u'renamed')
+
+        assert item.meta[NAME] == [u'First', 'Third', 'Fourth', 'Fifth']
+
     def test_rename_recursion(self):
         update_item(u'Page', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Page 1')
         update_item(u'Page/Child', {CONTENTTYPE: u'text/x.moin.wiki'}, u'this is child')