profile_list_block_test.rb
4.5 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require File.dirname(__FILE__) + '/../test_helper'
class ProfileListBlockTest < Test::Unit::TestCase
should 'describe itself' do
assert_not_equal Block.description, ProfileListBlock.description
end
should 'provide a default title' do
assert_not_equal Block.new.default_title, ProfileListBlock.new.default_title
end
should 'accept a limit of people to be displayed (and default to 6)' do
block = ProfileListBlock.new
assert_equal 6, block.limit
block.limit = 20
assert_equal 20, block.limit
end
should 'list people' do
User.destroy_all
person1 = create_user('testperson1').person
person2 = create_user('testperson2').person
person3 = create_user('testperson3').person
owner = Environment.create!(:name => 'test env')
block = ProfileListBlock.new
owner.boxes.first.blocks << block
block.save!
profiles = [person1, person3]
block.expects(:profiles).returns(profiles)
self.expects(:profile_image_link).with(person1).once
self.expects(:profile_image_link).with(person2).never
self.expects(:profile_image_link).with(person3).once
self.expects(:content_tag).returns('<div></div>').at_least_once
self.expects(:block_title).returns('block title').at_least_once
assert_kind_of String, instance_eval(&block.content)
end
should 'list private profiles' do
env = Environment.create!(:name => 'test env')
profile1 = fast_create(Profile, :environment_id => env.id)
profile2 = fast_create(Profile, :environment_id => env.id, :public_profile => false) # private profile
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
ids = block.profile_finder.ids
assert_includes ids, profile1.id
assert_includes ids, profile2.id
end
should 'not list invisible profiles' do
env = Environment.create!(:name => 'test env')
profile1 = fast_create(Profile, :environment_id => env.id)
profile2 = fast_create(Profile, :environment_id => env.id, :visible => false) # not visible profile
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
ids = block.profile_finder.ids
assert_includes ids, profile1.id
assert_not_includes ids, profile2.id
end
should 'use finders to find profiles to be listed' do
block = ProfileListBlock.new
finder = mock
block.expects(:profile_finder).returns(finder).once
finder.expects(:find)
block.profiles
end
should 'provide random numbers' do
assert_respond_to ProfileListBlock::Finder.new(nil), :pick_random
end
should 'provide view_title' do
env = Environment.create!(:name => 'test env')
block = ProfileListBlock.new(:title => 'Title from block')
env.boxes.first.blocks << block
block.save!
assert_equal 'Title from block', block.view_title
end
should 'provide view title with variables' do
env = Environment.create!(:name => 'test env')
block = ProfileListBlock.new(:title => '{#} members')
env.boxes.first.blocks << block
block.save!
assert_equal '0 members', block.view_title
end
should 'count number of public and private profiles' do
env = Environment.create!(:name => 'test env')
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
priv_p = fast_create(Person, :environment_id => env.id, :public_profile => false)
pub_p = fast_create(Person, :environment_id => env.id, :public_profile => true)
priv_c = fast_create(Community, :public_profile => false, :environment_id => env.id)
pub_c = fast_create(Community, :public_profile => true , :environment_id => env.id)
priv_e = fast_create(Enterprise, :public_profile => false , :environment_id => env.id)
pub_e = fast_create(Enterprise, :public_profile => true , :environment_id => env.id)
assert_equal 6, block.profile_count
end
should 'only count number of visible profiles' do
env = Environment.create!(:name => 'test env')
block = ProfileListBlock.new
env.boxes.first.blocks << block
block.save!
priv_p = fast_create(Person, :environment_id => env.id, :visible => false)
pub_p = fast_create(Person, :environment_id => env.id, :visible => true)
priv_c = fast_create(Community, :visible => false, :environment_id => env.id)
pub_c = fast_create(Community, :visible => true , :environment_id => env.id)
priv_e = fast_create(Enterprise, :visible => false , :environment_id => env.id)
pub_e = fast_create(Enterprise, :visible => true , :environment_id => env.id)
assert_equal 3, block.profile_count
end
end