<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -42,19 +42,17 @@ module Taggable
 			tags = tags.strip.split(TAG_SEPARATOR)
 		end
 
-		tags = tags.delete_if { |tag|
-			AppConfig.TAG_BLACKLIST.include? tag
-        }
+		tags = tags.delete_if do |tag|
+			tag.empty? or AppConfig.TAG_BLACKLIST.include?(tag)
+		end
 
 		return if not tags or tags.empty?
 
 		# delete this thing's existing taggings
-		self.class.tagging_class.find_all_by_thing_id(self).each do |t|
-			t.destroy
-		end
+		self.class.tagging_class.destroy_all(:thing_id =&gt; self)
 
 		tags.uniq.each do |tag|
-			add_tag tag
+			self.add_tag tag
 		end
 	end
 
@@ -70,7 +68,7 @@ module Taggable
 	end
 
 	# an Item's tags, as an Array of Strings
-	def tags
-		taggings.map { |t| t.to_s }
+	def tags(use_cached = false)
+		taggings(use_cached).map { |t| t.to_s }
 	end
 end</diff>
      <filename>lib/taggable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,8 +14,12 @@ class ItemTest &lt; ActiveSupport::TestCase
 		tags = htc.tags.sort
 		assert_equal ['politics', 'spain'], tags
 
+		# an item's tags can be replaced
 		htc.tag_with ['nonfiction']
 
+		tags = htc.tags(true) # 'true' means refresh the cache
+		assert_equal ['nonfiction'], tags
+
 		# items can be found by tag
 		tagged_with = Item.find_by_tag('nonfiction')
 
@@ -23,6 +27,24 @@ class ItemTest &lt; ActiveSupport::TestCase
 		assert_equal htc, tagged_with[0]
 	end
 
+	def test_bad_tagging
+		htc = items(:htc)
+
+		# duplicate tags only get stored once
+		htc.tag_with ['xyz', 'xyz', 'zyx']
+		assert_equal ['xyz', 'zyx'], htc.tags(true).sort
+
+		# can't tag an item with blacklisted tags
+		AppConfig.TAG_BLACKLIST = ['x', 'y', 'xyzzy']
+
+		htc.tag_with [ 'a', 'x', 'b', 'why', 'xyzzy', 'z']
+		assert_equal [ 'a', 'b', 'why', 'z' ], htc.tags(true).sort
+
+		# can't tag an item with blank tags
+		htc.tag_with [ '', 'and so on.', ]
+		assert_equal ['and so on.'], htc.tags(true).sort
+	end
+
 	def test_current_loan
 		lhd = items(:lhd)
 		bct = users(:bct)</diff>
      <filename>test/unit/item_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e25fe2084c387a7b7e1104779361bba6d80a835b</id>
    </parent>
  </parents>
  <author>
    <name>Brendan Taylor</name>
    <email>whateley@gmail.com</email>
  </author>
  <url>http://github.com/medwards/free-library-on-rails/commit/7244eb5534e04ac05b14330d26ab7c8ac55275af</url>
  <id>7244eb5534e04ac05b14330d26ab7c8ac55275af</id>
  <committed-date>2009-09-05T05:17:45-07:00</committed-date>
  <authored-date>2009-09-05T05:17:45-07:00</authored-date>
  <message>drop blank tags.</message>
  <tree>d27814a98ebacf2e565efd52487cca8b5489d0b5</tree>
  <committer>
    <name>Brendan Taylor</name>
    <email>whateley@gmail.com</email>
  </committer>
</commit>
