This commit is contained in:
Matt Rogers 2013-03-01 16:49:53 -06:00
commit 8b0f3e986a
9 changed files with 159 additions and 77 deletions

View file

@ -0,0 +1,31 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class TagCloudQueryTest < ActiveSupport::TestCase
fixtures :tags, :taggings, :users
def user
@user ||= User.find 1
end
def test_get_all_tags
tags = Stats::TagCloudQuery.new(user).result
assert_equal 2, tags.size
tags.sort_by! {|t| t.id}
tag = tags.first
assert_equal 3, tag.count
assert_equal "foo", tag.name
tag = tags.last
assert_equal 1, tag.count
assert_equal "bar", tag.name
end
def test_get_subset_of_tags
tags = Stats::TagCloudQuery.new(user, 1.week.ago).result
assert_equal 1, tags.size
assert_equal 2, tags.first.count
assert_equal "foo", tags.first.name
end
end

View file

@ -0,0 +1,23 @@
require File.expand_path(File.dirname(__FILE__) + '/../minimal_test_helper')
require 'app/models/stats/tag_cloud'
class TagCloudTest < Test::Unit::TestCase
FakeTag = Struct.new(:name, :count)
def test_tags_get_sorted_alphabetically
tags = [FakeTag.new("bee", 1), FakeTag.new("See", 10), FakeTag.new("aye", 100)]
assert_equal %w(aye bee See), Stats::TagCloud.new(tags).tags.map(&:name)
end
def test_tag_font_size
tags = [FakeTag.new("bee", 1), FakeTag.new("See", 10), FakeTag.new("aye", 100)]
cloud = Stats::TagCloud.new(tags)
assert_equal 9, cloud.font_size(FakeTag.new("whatever", 1))
assert_equal 18, cloud.font_size(FakeTag.new("whatever", 50))
assert_equal 28, cloud.font_size(FakeTag.new("whatever", 100))
end
end