profile_controller_test.rb
6 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
149
150
151
152
153
154
155
156
157
158
159
160
161
require File.dirname(__FILE__) + '/../test_helper'
require 'profile_controller'
# Re-raise errors caught by the controller.
class ProfileController; def rescue_action(e) raise e end; end
class ProfileControllerTest < Test::Unit::TestCase
def setup
@controller = ProfileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@profile = create_user('testuser').person
end
def test_local_files_reference
assert_local_files_reference
end
def test_valid_xhtml
assert_valid_xhtml
end
noosfero_test :profile => 'testuser'
should 'list friends' do
get :friends
assert_response :success
assert_template 'friends'
assert_kind_of Array, assigns(:friends)
end
should 'list communities' do
get :communities
assert_response :success
assert_template 'communities'
assert_kind_of Array, assigns(:communities)
end
should 'list enterprises' do
get :enterprises
assert_response :success
assert_template 'enterprises'
assert_kind_of Array, assigns(:enterprises)
end
should 'list members (for organizations)' do
get :members
assert_response :success
assert_template 'members'
assert_kind_of Array, assigns(:members)
end
should 'show Join This Community button for non-member users' do
login_as(@profile.identifier)
community = Community.create!(:name => 'my test community')
get :index, :profile => community.identifier
assert_tag :tag => 'a', :content => 'Join this community'
end
should 'not show Join This Community button for member users' do
login_as(@profile.identifier)
community = Community.create!(:name => 'my test community')
community.add_member(@profile)
get :index, :profile => community.identifier
assert_no_tag :tag => 'a', :content => 'Join this community'
end
should 'not show Join This Community button for non-registered users' do
community = Community.create!(:name => 'my test community')
get :index, :profile => community.identifier
assert_no_tag :tag => 'a', :content => 'Join this community'
end
should 'dont show enterprises link to enterprise' do
ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
get :index, :profile => ent.identifier
assert_tag :tag => 'h2', :content => "#{ent.identifier}'s profile"
assert_no_tag :tag => 'a', :content => 'Enterprises', :attributes => { :href => /profile\/#{ent.identifier}\/enterprises$/ }
end
should 'dont show members link to person' do
person = create_user('person_1').person
get :index, :profile => person.identifier
assert_tag :tag => 'h2', :content => "#{person.identifier}'s profile"
assert_no_tag :tag => 'a', :content => 'Members', :attributes => { :href => /profile\/#{person.identifier}\/members$/ }
end
should 'show friends link to person' do
person = create_user('person_1').person
get :index, :profile => person.identifier
assert_tag :tag => 'a', :content => 'Friends', :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
end
should 'not show homepage and feed automatically created on recent content' do
person = create_user('person_1').person
get :index, :profile => person.identifier
assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => '' }
end
should 'show homepage on recent content after update' do
person = create_user('person_1').person
person.home_page.name = 'Changed name'
assert person.home_page.save!
get :index, :profile => person.identifier
assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.home_page.name}/ }
end
should 'show feed on recent content after update' do
person = create_user('person_1').person
person.articles.find_by_path('feed').name = 'Changed name'
assert person.articles.find_by_path('feed').save!
get :index, :profile => person.identifier
assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.articles.find_by_path('feed').name}/ }
end
should 'display tag for profile' do
@profile.articles.create!(:name => 'testarticle', :tag_list => 'tag1')
get :tag, :profile => @profile.identifier, :id => 'tag1'
assert_tag :tag => 'a', :attributes => { :href => /testuser\/testarticle$/ }
end
should 'link to the same tag but for whole environment' do
@profile.articles.create!(:name => 'testarticle', :tag_list => 'tag1')
get :tag, :profile => @profile.identifier, :id => 'tag1'
assert_tag :tag => 'a', :attributes => { :href => '/tag/tag1' }, :content => 'See content tagged with "tag1" in the entire site'
end
should 'show a link to own control panel' do
login_as(@profile.identifier)
get :index, :profile => @profile.identifier
assert_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
end
should 'not show a link to others control panel' do
login_as(@profile.identifier)
other = create_user('person_1').person
get :index, :profile => other.identifier
assert_no_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' }
end
should 'show create community in own profile' do
login_as(@profile.identifier)
get :communities, :profile => @profile.identifier
assert_tag :tag => 'a', :child => { :tag => 'span', :content => 'Create a new community' }
end
should 'not show create community on profile of other users' do
login_as(@profile.identifier)
person = create_user('person_1').person
get :communities, :profile => person.identifier
assert_no_tag :tag => 'a', :child => { :tag => 'span', :content => 'Create a new community' }
end
end