Commit 565789d3f6d9a9c08fa087dc1a667ddd8bbb76ef
1 parent
5acb61dd
Exists in
master
and in
22 other branches
improved functional tests in community block plugin
Showing
4 changed files
with
134 additions
and
48 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -1250,11 +1250,19 @@ module ApplicationHelper |
1250 | 1250 | already_reported_message = _('You already reported this profile.') |
1251 | 1251 | report_profile_message = _('Report this profile for abusive behaviour') |
1252 | 1252 | |
1253 | - if type == :button | |
1253 | + if type == :button || type == :button_without_text | |
1254 | 1254 | if user.already_reported?(profile) |
1255 | - button(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) | |
1255 | + if type == :button | |
1256 | + button(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) | |
1257 | + elsif type == :button_without_text | |
1258 | + button_without_text(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) | |
1259 | + end | |
1256 | 1260 | else |
1257 | - button(:alert, text, url, :class => klass, :title => report_profile_message) | |
1261 | + if type == :button | |
1262 | + button(:alert, text, url, :class => klass, :title => report_profile_message) | |
1263 | + elsif type == :button_without_text | |
1264 | + button_without_text(:alert, text, url, :class => klass, :title => report_profile_message) | |
1265 | + end | |
1258 | 1266 | end |
1259 | 1267 | elsif type == :link |
1260 | 1268 | if user.already_reported?(profile) | ... | ... |
plugins/community_block/public/style.css
plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb
... | ... | @@ -15,10 +15,12 @@ class ProfileControllerTest < ActionController::TestCase |
15 | 15 | @request = ActionController::TestRequest.new |
16 | 16 | @response = ActionController::TestResponse.new |
17 | 17 | |
18 | - #user = create_user('testinguser') | |
19 | - #login_as(user.login) | |
18 | + @user = create_user('testinguser').person | |
19 | + login_as(@user.identifier) | |
20 | 20 | |
21 | 21 | @community = fast_create(Community, :environment_id => Environment.default) |
22 | + @community.add_member @user | |
23 | + @community.add_admin @user | |
22 | 24 | |
23 | 25 | @environment = @community.environment |
24 | 26 | @environment.enabled_plugins = ['CommunityBlock'] |
... | ... | @@ -36,31 +38,81 @@ class ProfileControllerTest < ActionController::TestCase |
36 | 38 | @community.save! |
37 | 39 | end |
38 | 40 | |
39 | - attr_accessor :profile, :block, :community | |
40 | - | |
41 | - should 'display community-block-logo class in community block' do | |
42 | - get :index, :profile => community.identifier | |
41 | + should 'display community-block' do | |
42 | + get :index, :profile => @community.identifier | |
43 | 43 | assert_tag :div, :attributes => {:class => 'community-block-logo'} |
44 | + assert_tag :div, :attributes => {:class => 'community-block-info'} | |
45 | + assert_tag :h1, :attributes => {:class => 'community-block-title'} | |
46 | + assert_tag :div, :attributes => {:class => 'community-block-description'} | |
47 | + assert_tag :div, :attributes => {:class => 'community-block-buttons'} | |
44 | 48 | end |
45 | 49 | |
46 | - should 'display community-block-info class in community block' do | |
47 | - get :index, :profile => community.identifier | |
48 | - assert_tag :div, :attributes => {:class => 'community-block-info'} | |
50 | + | |
51 | + # USER LOGGED IN AND COMMUNITY MEMBER # | |
52 | + | |
53 | + should 'display *leave* button when the user is logged in and is a member of the community' do | |
54 | + get :index, :profile => @community.identifier | |
55 | + assert_tag :a, :attributes => {:class => 'button icon-remove'} | |
49 | 56 | end |
50 | 57 | |
51 | - should 'display community-block-title class in community block' do | |
52 | - get :index, :profile => community.identifier | |
53 | - assert_tag :h1, :attributes => {:class => 'community-block-title'} | |
58 | + should 'display *send email to administrators* button when the user is logged in and is a member of the community' do | |
59 | + get :index, :profile => @community.identifier | |
60 | + assert_tag :a, :attributes => {:class => 'button icon-menu-mail'} | |
54 | 61 | end |
55 | 62 | |
56 | - should 'display community-block-description class in community block' do | |
57 | - get :index, :profile => community.identifier | |
58 | - assert_tag :div, :attributes => {:class => 'community-block-description'} | |
63 | + should 'display *report* button when the user is logged in and is a member of the community' do | |
64 | + get :index, :profile => @community.identifier | |
65 | + assert_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} | |
59 | 66 | end |
60 | 67 | |
61 | - should 'display community-block-buttons class in community block' do | |
62 | - get :index, :profile => community.identifier | |
63 | - assert_tag :div, :attributes => {:class => 'community-block-buttons'} | |
68 | + | |
69 | + # USER LOGGED IN AND NOT MEMBER OF THE COMMUNITY | |
70 | + | |
71 | + should 'display *join* button when the user is logged in and is not a member of the community' do | |
72 | + @community.remove_member @user | |
73 | + get :index, :profile => @community.identifier | |
74 | + assert_tag :a, :attributes => {:class => 'button icon-add'} | |
75 | + end | |
76 | + | |
77 | + should 'display *send email to administrators* button when the user is logged in and is not a member of the community' do | |
78 | + @community.remove_member @user | |
79 | + get :index, :profile => @community.identifier | |
80 | + assert_tag :a, :attributes => {:class => 'button icon-menu-mail'} | |
81 | + end | |
82 | + | |
83 | + should 'display *report* button when the user is logged in and is not a member of the community' do | |
84 | + @community.remove_member @user | |
85 | + get :index, :profile => @community.identifier | |
86 | + assert_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} | |
87 | + end | |
88 | + | |
89 | + | |
90 | + # USER LOGGED IN AND COMMUNITY ADMIN | |
91 | + | |
92 | + should 'display *configure* button when the user is logged in and is community admin' do | |
93 | + get :index, :profile => @community.identifier | |
94 | + assert_tag :a, :attributes => {:class => 'button icon-menu-ctrl-panel'} | |
95 | + end | |
96 | + | |
97 | + | |
98 | + # USER NOT LOGGED IN | |
99 | + | |
100 | + should 'not display *send email to administrators* button when the user is not logged in' do | |
101 | + logout | |
102 | + get :index, :profile => @community.identifier | |
103 | + assert_no_tag :a, :attributes => {:class => 'button icon-menu-mail'} | |
104 | + end | |
105 | + | |
106 | + should 'not display *report* button when the user is not logged in' do | |
107 | + logout | |
108 | + get :index, :profile => @community.identifier | |
109 | + assert_no_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} | |
110 | + end | |
111 | + | |
112 | + should 'not display *configure* button when the user is logged in and is admin of the community' do | |
113 | + logout | |
114 | + get :index, :profile => @community.identifier | |
115 | + assert_no_tag :a, :attributes => {:class => 'button icon-menu-ctrl-panel link-this-page'} | |
64 | 116 | end |
65 | 117 | |
66 | 118 | end | ... | ... |
plugins/community_block/views/community_block.rhtml
... | ... | @@ -5,34 +5,58 @@ |
5 | 5 | <div class="community-block-info"> |
6 | 6 | <h1 class="community-block-title"><%=profile.name%></h1> |
7 | 7 | <div class="community-block-description"><%= profile.description %></div> |
8 | - <div class="community-block-buttons"> | |
9 | - <% if logged_in? %> | |
10 | - <% if profile.members.include?(user) %> | |
11 | - <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, | |
12 | - :class => 'leave-community', | |
13 | - :title => _("Leave community"), | |
8 | + </div> | |
9 | + <div style="clear:both"></div> | |
10 | + <div class="community-block-buttons"> | |
11 | + <% if logged_in? %> | |
12 | + | |
13 | + <% if profile.members.include?(user) || profile.already_request_membership?(user) %> | |
14 | + <%= button_without_text( | |
15 | + :remove, | |
16 | + __('Leave community'), | |
17 | + profile.leave_url, | |
18 | + :title => _("Leave community"), | |
19 | + :style => 'position: relative;') %> | |
20 | + <% else %> | |
21 | + <%= button_without_text( | |
22 | + :add, | |
23 | + __('Join community'), | |
24 | + profile.join_url, | |
25 | + :title => _("Join community"), | |
26 | + :style => 'position: relative;') %> | |
27 | + <% end %> | |
28 | + | |
29 | + <% if profile.enable_contact? %> | |
30 | + <%= button_without_text( | |
31 | + :'menu-mail', | |
32 | + __('Send an e-mail'), | |
33 | + { :profile => profile.identifier, | |
34 | + :controller => 'contact', | |
35 | + :action => 'new' }, | |
36 | + :title => _('Send an e-mail to the administrators'), | |
37 | + :stle => 'position: relative;') %> | |
38 | + <% end %> | |
39 | + | |
40 | + <%= report_abuse(profile, :button_without_text) %> | |
41 | + | |
42 | + <% if !user.nil? && user.has_permission?('edit_profile', profile) %> | |
43 | + | |
44 | + <%= button_without_text( | |
45 | + :'menu-ctrl-panel', | |
46 | + __('Control Panel'), | |
47 | + profile.admin_url, | |
48 | + :title => _('Configure this community'), | |
14 | 49 | :style => 'position: relative;') %> |
15 | - <%= button(:add, content_tag('span', __('Join')), profile.join_url, | |
16 | - :class => 'join-community', | |
17 | - :title => _("Join community"), | |
18 | - :style => 'position: relative; display: none;') %> | |
19 | - <% else %> | |
20 | - <% unless profile.already_request_membership?(user) %> | |
21 | - <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, | |
22 | - :class => 'leave-community', | |
23 | - :title => _("Leave community"), | |
24 | - :style => 'position: relative; display: none;') %> | |
25 | - <%= button(:add, content_tag('span', __('Join')), profile.join_url, | |
26 | - :class => 'join-community', | |
50 | + | |
51 | + <% end %> | |
52 | + | |
53 | + <% else %> | |
54 | + <%= button_without_text( | |
55 | + :add, | |
56 | + __('Join community'), | |
57 | + profile.join_not_logged_url, | |
27 | 58 | :title => _("Join community"), |
28 | 59 | :style => 'position: relative;') %> |
29 | - <% end %> | |
30 | - <% end %> | |
31 | - | |
32 | - <% else %> | |
33 | - <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, :class => 'button with-text icon-add', :title => _("Join comunity") %> | |
34 | - <% end %> | |
35 | - </div> | |
60 | + <% end %> | |
36 | 61 | </div> |
37 | - <div style="clear:both"></div> | |
38 | 62 | </div> | ... | ... |