diff --git a/CHANGELOG b/CHANGELOG index b27e142..a6acc52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +[23 October 2007] + +* Fix tag_cloud when no tags are present. + [22 October 2007] * Fix find_tagged_with using :match_all and :include. diff --git a/lib/tags_helper.rb b/lib/tags_helper.rb index d091229..d5644b7 100644 --- a/lib/tags_helper.rb +++ b/lib/tags_helper.rb @@ -1,6 +1,8 @@ module TagsHelper # See the README for an example using tag_cloud. def tag_cloud(tags, classes) + return if tags.empty? + max_count = tags.sort_by(&:count).last.count.to_f tags.each do |tag| diff --git a/test/tags_helper_test.rb b/test/tags_helper_test.rb index 42b033f..9c3ce53 100644 --- a/test/tags_helper_test.rb +++ b/test/tags_helper_test.rb @@ -8,7 +8,7 @@ class TagsHelperTest < Test::Unit::TestCase def test_tag_cloud cloud_elements = [] - tag_cloud(Post.tag_counts, %w(css1 css2 css3 css4)) do |tag, css_class| + tag_cloud Post.tag_counts, %w(css1 css2 css3 css4) do |tag, css_class| cloud_elements << [tag, css_class] end @@ -19,4 +19,10 @@ def test_tag_cloud [tags(:question), "css1"] ], cloud_elements end + + def test_tag_cloud_when_no_tags + tag_cloud SpecialPost.tag_counts, %w(css1) do + assert false, "tag_cloud should not yield" + end + end end