community_test.rb
5.22 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
136
137
138
139
140
141
142
143
144
145
146
147
148
require File.dirname(__FILE__) + '/../test_helper'
class CommunityTest < Test::Unit::TestCase
should 'inherit from Profile' do
assert_kind_of Profile, Community.new
end
should 'convert name into identifier' do
c = Community.new(:environment => Environment.default, :name =>'My shiny new Community')
assert_equal 'My shiny new Community', c.name
assert_equal 'my-shiny-new-community', c.identifier
end
should 'have a description attribute' do
c = Community.new(:environment => Environment.default)
c.description = 'the description of the community'
assert_equal 'the description of the community', c.description
end
should 'create default set of blocks' do
c = Community.create!(:environment => Environment.default, :name => 'my new community')
assert c.boxes[0].blocks.map(&:class).include?(MainBlock)
assert c.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock)
assert c.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock)
assert c.boxes[2].blocks.map(&:class).include?(MembersBlock)
assert c.boxes[2].blocks.map(&:class).include?(TagsBlock)
assert_equal 5, c.blocks.size
end
should 'get a default home page and RSS feed' do
community = Community.create!(:environment => Environment.default, :name => 'my new community')
assert_kind_of Article, community.home_page
assert_kind_of RssFeed, community.articles.find_by_path('feed')
end
should 'have contact_person' do
community = Community.new(:environment => Environment.default, :name => 'my new community')
assert_respond_to community, :contact_person
end
should 'allow to add new members' do
c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile')
p = create_user('mytestuser').person
c.add_member(p)
assert c.members.include?(p), "Community should add the new member"
end
should 'allow to remove members' do
c = Community.create!(:environment => Environment.default, :name => 'my other test profile', :identifier => 'myothertestprofile')
p = create_user('myothertestuser').person
c.add_member(p)
assert_includes c.members, p
c.remove_member(p)
c.reload
assert_not_includes c.members, p
end
should 'clear relationships after destroy' do
c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile')
member = create_user('memberuser').person
admin = create_user('adminuser').person
moderator = create_user('moderatoruser').person
c.add_member(member)
c.add_admin(admin)
c.add_moderator(moderator)
relationships = c.role_assignments
assert_not_nil relationships
c.destroy
relationships.each do |i|
assert !RoleAssignment.exists?(i.id)
end
end
should 'have a community template' do
env = Environment.create!(:name => 'test env')
p = Community.create!(:environment => Environment.default, :name => 'test_com', :identifier => 'test_com', :environment => env)
assert_kind_of Community, p.template
end
should 'return active_community_fields' do
e = Environment.default
e.expects(:active_community_fields).returns(['contact_phone', 'contact_email']).at_least_once
ent = Community.new(:environment => e)
assert_equal e.active_community_fields, ent.active_fields
end
should 'return required_community_fields' do
e = Environment.default
e.expects(:required_community_fields).returns(['contact_phone', 'contact_email']).at_least_once
community = Community.new(:environment => e)
assert_equal e.required_community_fields, community.required_fields
end
should 'require fields if community needs' do
e = Environment.default
e.expects(:required_community_fields).returns(['contact_phone']).at_least_once
community = Community.new(:environment => e)
assert ! community.valid?
assert community.errors.invalid?(:contact_phone)
community.contact_phone = '99999'
community.valid?
assert ! community.errors.invalid?(:contact_phone)
end
should 'return newest text articles as news' do
c = Community.create!(:name => 'test_com')
f = Folder.create!(:name => 'folder', :profile => c)
u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
older_t = TinyMceArticle.create!(:name => 'old news', :profile => c)
t = TinyMceArticle.create!(:name => 'news', :profile => c)
t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f)
assert_equal [t_in_f, t], c.news(2)
end
should 'not return highlighted news when not asked' do
c = Community.create!(:name => 'test_com')
highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true)
t = TinyMceArticle.create!(:name => 'news', :profile => c)
assert_equal [t].map(&:slug), c.news(2).map(&:slug)
end
should 'return highlighted news when asked' do
c = Community.create!(:name => 'test_com')
highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true)
t = TinyMceArticle.create!(:name => 'news', :profile => c)
assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug)
end
end