[Nitro] Bug in Taggable and .delete_all_tags

Jonathan Buch john at oxyliquit.de
Sun Aug 27 18:51:25 EDT 2006


bug in taggable in 0.40.

assert_equal 0, a1.tags.size

assert_equal 4, Tag.count # << raises, sais 3

While writing that and debugging while doing it I found the bug in  
taggable.  The problem is, that the 'tags' array and the tags inside don't  
get reloaded, even if a new tag was added and incremented the `.count`.   
Solution would be, to add a `tag.reload` before doing the `tag.unlink`.

   def delete_all_tags
     for tag in tags

Not sure if I like it, it's not really efficient, too many roundtrips to  
DB.  Hypothetically: could `Tag` (or any other entity) be told to always  
return the "same" (same `.object_id`) Object instead of a new one?  The  
information would be shared then and wouldn't have to be reloaded, but I'm  
really not sure how this would work, I guess one would need caching...

A side note: should `.reload` return the object instead of a Fixnum as it  
does right now?

Anyway, attached is a patch which adds the reload and the test case, nasty  
thing took me quite some time to find out why it deleted every tag and not  
just the 2, wasted time ;/


Feel the love
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tagfix.ptch.tar.bz2
Type: application/bzip2
Size: 6627 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/nitro-general/attachments/20060828/e36a8de7/attachment.bin 

More information about the Nitro-general mailing list