mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-20 17:20:12 +01:00
Add unit test for tag cloud
This commit is contained in:
parent
63fb7a589c
commit
a13199cdda
5 changed files with 34 additions and 7 deletions
|
|
@ -555,8 +555,8 @@ class StatsController < ApplicationController
|
||||||
tags = Stats::TagCloudQuery.new(current_user).result
|
tags = Stats::TagCloudQuery.new(current_user).result
|
||||||
@tag_cloud = Stats::TagCloud.new(tags)
|
@tag_cloud = Stats::TagCloud.new(tags)
|
||||||
|
|
||||||
tags_90days = Stats::TagCloudQuery.new(current_user, @cut_off_3months).result
|
tags = Stats::TagCloudQuery.new(current_user, @cut_off_3months).result
|
||||||
@tag_cloud_90days = Stats::TagCloud.new(tags_90days)
|
@tag_cloud_90days = Stats::TagCloud.new(tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ids_from (actions, week_from, week_to, at_end)
|
def get_ids_from (actions, week_from, week_to, at_end)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ module Stats
|
||||||
end
|
end
|
||||||
|
|
||||||
def font_size(tag)
|
def font_size(tag)
|
||||||
(9 + 2*(tag.count.to_i-min)/divisor)
|
(9 + 2*(tag.count-min)/divisor)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
7
test/minimal_test_helper.rb
Normal file
7
test/minimal_test_helper.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'simplecov'
|
||||||
|
SimpleCov.start 'rails'
|
||||||
|
|
||||||
|
ENV["RAILS_ENV"] = "test"
|
||||||
|
require 'test/unit'
|
||||||
|
|
||||||
|
$:.unshift File.dirname(File.dirname(__FILE__))
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
require 'simplecov'
|
require File.expand_path('../minimal_test_helper', __FILE__)
|
||||||
SimpleCov.start 'rails'
|
|
||||||
|
|
||||||
ENV["RAILS_ENV"] = "test"
|
|
||||||
require File.expand_path('../../config/environment', __FILE__)
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
require 'rails/test_help'
|
require 'rails/test_help'
|
||||||
|
|
||||||
|
|
|
||||||
23
test/unit/tag_cloud_test.rb
Normal file
23
test/unit/tag_cloud_test.rb
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue