Add unit test for tag cloud

This commit is contained in:
Katrina Owen 2013-03-01 16:03:35 -05:00
parent 63fb7a589c
commit a13199cdda
5 changed files with 34 additions and 7 deletions

View file

@ -555,8 +555,8 @@ class StatsController < ApplicationController
tags = Stats::TagCloudQuery.new(current_user).result
@tag_cloud = Stats::TagCloud.new(tags)
tags_90days = Stats::TagCloudQuery.new(current_user, @cut_off_3months).result
@tag_cloud_90days = Stats::TagCloud.new(tags_90days)
tags = Stats::TagCloudQuery.new(current_user, @cut_off_3months).result
@tag_cloud_90days = Stats::TagCloud.new(tags)
end
def get_ids_from (actions, week_from, week_to, at_end)

View file

@ -14,7 +14,7 @@ module Stats
end
def font_size(tag)
(9 + 2*(tag.count.to_i-min)/divisor)
(9 + 2*(tag.count-min)/divisor)
end
private

View file

@ -0,0 +1,7 @@
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] = "test"
require 'test/unit'
$:.unshift File.dirname(File.dirname(__FILE__))

View file

@ -1,7 +1,4 @@
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] = "test"
require File.expand_path('../minimal_test_helper', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

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