Commits

Anonymous committed 728dd1b

tag fixes

  • Participants
  • Parent commits 1788b8e

Comments (0)

Files changed (2)

File newsmeme/models.py

         self._tags = tags
 
         if self.id:
-            db.delete(post_tags, post_tags.c.post_id==self.id)
+            d = db.delete(post_tags, post_tags.c.post_id==self.id)
+            db.engine.execute(d)
 
         for tag in self.taglist:
 
         if self.tags is None:
             return []
 
-        return [t.strip() for t in self.tags.split(",")]
+        tags = [t.strip() for t in self.tags.split(",")]
+        return [t for t in tags if t]
 
     @cached_property
     def linked_taglist(self):

File tests/test_models.py

         assert _count_post_tags() == 3
 
         self.post.tags = "music, iPhone, books"
+        db.session.commit()
+
+        for t in Tag.query.all():
+            if t.name in ("music", "iphone", "books"):
+                assert t.num_posts == 1
+            
+            if t.name in ("comedy", "it crowd"):
+                assert t.num_posts == 0
 
         assert _count_post_tags() == 3
+        
+        self.post.tags = ""
 
+        assert _count_post_tags() == 0
 
     def test_update_num_comments(self):
 
         votes.add(1)
         
         self.post.votes = votes
-        print self.post.votes
 
         assert 1 in self.post.votes