From 565789d3f6d9a9c08fa087dc1a667ddd8bbb76ef Mon Sep 17 00:00:00 2001 From: Francisco Marcelo A. Lima JĂșnior Date: Mon, 4 Nov 2013 20:07:30 -0300 Subject: [PATCH] improved functional tests in community block plugin --- app/helpers/application_helper.rb | 14 +++++++++++--- plugins/community_block/public/style.css | 4 +++- plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ plugins/community_block/views/community_block.rhtml | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- 4 files changed, 134 insertions(+), 48 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d193b73..160da6d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1250,11 +1250,19 @@ module ApplicationHelper already_reported_message = _('You already reported this profile.') report_profile_message = _('Report this profile for abusive behaviour') - if type == :button + if type == :button || type == :button_without_text if user.already_reported?(profile) - button(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) + if type == :button + button(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) + elsif type == :button_without_text + button_without_text(:alert, text, url, :class => klass+' disabled', :disabled => true, :title => already_reported_message) + end else - button(:alert, text, url, :class => klass, :title => report_profile_message) + if type == :button + button(:alert, text, url, :class => klass, :title => report_profile_message) + elsif type == :button_without_text + button_without_text(:alert, text, url, :class => klass, :title => report_profile_message) + end end elsif type == :link if user.already_reported?(profile) diff --git a/plugins/community_block/public/style.css b/plugins/community_block/public/style.css index 9da2b23..60df06f 100644 --- a/plugins/community_block/public/style.css +++ b/plugins/community_block/public/style.css @@ -38,6 +38,8 @@ #content .box-1 .community-block .community-block-buttons { //border: 1px solid #F00; - text-align: right; + text-align: left; + margin-top: 3px; + margin-left: 22px; } diff --git a/plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb b/plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb index 7f7794b..8ecb1e5 100644 --- a/plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb +++ b/plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb @@ -15,10 +15,12 @@ class ProfileControllerTest < ActionController::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new - #user = create_user('testinguser') - #login_as(user.login) + @user = create_user('testinguser').person + login_as(@user.identifier) @community = fast_create(Community, :environment_id => Environment.default) + @community.add_member @user + @community.add_admin @user @environment = @community.environment @environment.enabled_plugins = ['CommunityBlock'] @@ -36,31 +38,81 @@ class ProfileControllerTest < ActionController::TestCase @community.save! end - attr_accessor :profile, :block, :community - - should 'display community-block-logo class in community block' do - get :index, :profile => community.identifier + should 'display community-block' do + get :index, :profile => @community.identifier assert_tag :div, :attributes => {:class => 'community-block-logo'} + assert_tag :div, :attributes => {:class => 'community-block-info'} + assert_tag :h1, :attributes => {:class => 'community-block-title'} + assert_tag :div, :attributes => {:class => 'community-block-description'} + assert_tag :div, :attributes => {:class => 'community-block-buttons'} end - should 'display community-block-info class in community block' do - get :index, :profile => community.identifier - assert_tag :div, :attributes => {:class => 'community-block-info'} + + # USER LOGGED IN AND COMMUNITY MEMBER # + + should 'display *leave* button when the user is logged in and is a member of the community' do + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-remove'} end - should 'display community-block-title class in community block' do - get :index, :profile => community.identifier - assert_tag :h1, :attributes => {:class => 'community-block-title'} + should 'display *send email to administrators* button when the user is logged in and is a member of the community' do + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-menu-mail'} end - should 'display community-block-description class in community block' do - get :index, :profile => community.identifier - assert_tag :div, :attributes => {:class => 'community-block-description'} + should 'display *report* button when the user is logged in and is a member of the community' do + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} end - should 'display community-block-buttons class in community block' do - get :index, :profile => community.identifier - assert_tag :div, :attributes => {:class => 'community-block-buttons'} + + # USER LOGGED IN AND NOT MEMBER OF THE COMMUNITY + + should 'display *join* button when the user is logged in and is not a member of the community' do + @community.remove_member @user + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-add'} + end + + should 'display *send email to administrators* button when the user is logged in and is not a member of the community' do + @community.remove_member @user + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-menu-mail'} + end + + should 'display *report* button when the user is logged in and is not a member of the community' do + @community.remove_member @user + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} + end + + + # USER LOGGED IN AND COMMUNITY ADMIN + + should 'display *configure* button when the user is logged in and is community admin' do + get :index, :profile => @community.identifier + assert_tag :a, :attributes => {:class => 'button icon-menu-ctrl-panel'} + end + + + # USER NOT LOGGED IN + + should 'not display *send email to administrators* button when the user is not logged in' do + logout + get :index, :profile => @community.identifier + assert_no_tag :a, :attributes => {:class => 'button icon-menu-mail'} + end + + should 'not display *report* button when the user is not logged in' do + logout + get :index, :profile => @community.identifier + assert_no_tag :a, :attributes => {:class => 'button icon-alert report-abuse-action'} + end + + should 'not display *configure* button when the user is logged in and is admin of the community' do + logout + get :index, :profile => @community.identifier + assert_no_tag :a, :attributes => {:class => 'button icon-menu-ctrl-panel link-this-page'} end end diff --git a/plugins/community_block/views/community_block.rhtml b/plugins/community_block/views/community_block.rhtml index fd4bae6..310d48f 100644 --- a/plugins/community_block/views/community_block.rhtml +++ b/plugins/community_block/views/community_block.rhtml @@ -5,34 +5,58 @@

<%=profile.name%>

<%= profile.description %>
-
- <% if logged_in? %> - <% if profile.members.include?(user) %> - <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, - :class => 'leave-community', - :title => _("Leave community"), +
+
+
+ <% if logged_in? %> + + <% if profile.members.include?(user) || profile.already_request_membership?(user) %> + <%= button_without_text( + :remove, + __('Leave community'), + profile.leave_url, + :title => _("Leave community"), + :style => 'position: relative;') %> + <% else %> + <%= button_without_text( + :add, + __('Join community'), + profile.join_url, + :title => _("Join community"), + :style => 'position: relative;') %> + <% end %> + + <% if profile.enable_contact? %> + <%= button_without_text( + :'menu-mail', + __('Send an e-mail'), + { :profile => profile.identifier, + :controller => 'contact', + :action => 'new' }, + :title => _('Send an e-mail to the administrators'), + :stle => 'position: relative;') %> + <% end %> + + <%= report_abuse(profile, :button_without_text) %> + + <% if !user.nil? && user.has_permission?('edit_profile', profile) %> + + <%= button_without_text( + :'menu-ctrl-panel', + __('Control Panel'), + profile.admin_url, + :title => _('Configure this community'), :style => 'position: relative;') %> - <%= button(:add, content_tag('span', __('Join')), profile.join_url, - :class => 'join-community', - :title => _("Join community"), - :style => 'position: relative; display: none;') %> - <% else %> - <% unless profile.already_request_membership?(user) %> - <%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url, - :class => 'leave-community', - :title => _("Leave community"), - :style => 'position: relative; display: none;') %> - <%= button(:add, content_tag('span', __('Join')), profile.join_url, - :class => 'join-community', + + <% end %> + + <% else %> + <%= button_without_text( + :add, + __('Join community'), + profile.join_not_logged_url, :title => _("Join community"), :style => 'position: relative;') %> - <% end %> - <% end %> - - <% else %> - <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, :class => 'button with-text icon-add', :title => _("Join comunity") %> - <% end %> -
+ <% end %>
-
-- libgit2 0.21.2