environment_statistics_block_test.rb
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require File.dirname(__FILE__) + '/../test_helper'
class EnvironmentStatisticsBlockTest < Test::Unit::TestCase
should 'inherit from Block' do
assert_kind_of Block, EnvironmentStatisticsBlock.new
end
should 'describe itself' do
assert_not_equal Block.description, EnvironmentStatisticsBlock.description
end
should 'provide a default title' do
owner = mock
owner.expects(:name).returns('my environment')
block = EnvironmentStatisticsBlock.new
block.expects(:owner).returns(owner)
assert_equal 'Statistics for my environment', block.title
end
should 'generate statistics' do
env = Environment.create!(:name => "My test environment")
user1 = create_user('testuser1', :environment_id => env.id)
user2 = create_user('testuser2', :environment_id => env.id)
env.enterprises.build(:identifier => 'mytestenterprise', :name => 'My test enterprise').save!
env.communities.build(:identifier => 'mytestcommunity', :name => 'mytestcommunity').save!
block = EnvironmentStatisticsBlock.new
env.boxes.first.blocks << block
content = block.content
assert_match /One enterprise/, content
assert_match /2 users/, content
assert_match /One community/, content
end
should 'generate statistics but not for private profiles' do
env = Environment.create!(:name => "My test environment")
user1 = create_user('testuser1', :environment_id => env.id)
user2 = create_user('testuser2', :environment_id => env.id)
user3 = create_user('testuser3', :environment_id => env.id)
p = user3.person; p.public_profile = false; p.save!
env.enterprises.build(:identifier => 'mytestenterprise', :name => 'My test enterprise').save!
env.enterprises.build(:identifier => 'mytestenterprise2', :name => 'My test enterprise 2', :public_profile => false).save!
env.communities.build(:identifier => 'mytestcommunity', :name => 'mytestcommunity').save!
env.communities.build(:identifier => 'mytestcommunity2', :name => 'mytestcommunity 2', :public_profile => false).save!
block = EnvironmentStatisticsBlock.new
env.boxes.first.blocks << block
content = block.content
assert_match /One enterprise/, content
assert_match /2 users/, content
assert_match /One community/, content
end
end