diff --git a/plugins/community_block/test/functional/commmunity_block_plugin_profile_controller_test.rb b/plugins/community_block/test/functional/commmunity_block_plugin_profile_controller_test.rb new file mode 100644 index 0000000..649d859 --- /dev/null +++ b/plugins/community_block/test/functional/commmunity_block_plugin_profile_controller_test.rb @@ -0,0 +1,83 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class ProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + def rescue_action(e) + raise e + end +end + +class ProfileControllerTest < ActionController::TestCase + + def setup + @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'] + @environment.save! + + CommunityBlock.delete_all + @box1 = create(Box, :owner => @community) + @community.boxes = [@box1] + + @block = CommunityBlock.new + @block.box = @box1 + @block.save! + + @community.blocks<<@block + @community.save! + end + + 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 :div, :attributes => {:class => 'community-block-title'} + assert_tag :div, :attributes => {:class => 'community-block-description'} + end + + 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 :span, :attributes => {:class => 'community-block-button icon-remove'} + end + + 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_match /\{"Send an e-mail":\{"href":"\/contact\/#{@community.identifier}\/new"\}\}/, @response.body + end + + should 'display *report* button when the user is logged in and is a member of the community' do + get :index, :profile => @community.identifier + assert_match /\{"Report abuse":\{"href":"\/profile\/#{@community.identifier}\/report_abuse"\}\}/, @response.body + end + + 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 :span, :attributes => {:class => 'community-block-button icon-add'} + end + + should 'display *control panel* link option when the user is logged in and is community admin' do + get :index, :profile => @community.identifier + assert_match /\{"Control panel":\{"href":"\/myprofile\/#{@community.identifier}"\}\}/, @response.body + end + + should 'display *join* button when the user is not logged in' do + logout + get :index, :profile => @community.identifier + assert_tag :span, :attributes => {:class => 'community-block-button icon-add'} + end + + should 'not display *arrow* button when the user is not logged in' do + logout + get :index, :profile => @community.identifier + assert_no_tag :span, :attributes => {:class => 'community-block-button icon-arrow'} + end + +end 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 deleted file mode 100644 index c0c9fc9..0000000 --- a/plugins/community_block/test/functional/commmunity_block_plugin_profile_design_controller_test.rb +++ /dev/null @@ -1,87 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -# Re-raise errors caught by the controller. -class ProfileController - append_view_path File.join(File.dirname(__FILE__) + '/../../views') - def rescue_action(e) - raise e - end -end - -class ProfileControllerTest < ActionController::TestCase - - def setup - @controller = ProfileController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @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'] - @environment.save! - - CommunityBlock.delete_all - @box1 = create(Box, :owner => @community) - @community.boxes = [@box1] - - @block = CommunityBlock.new - @block.box = @box1 - @block.save! - - @community.blocks<<@block - @community.save! - end - - 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 :div, :attributes => {:class => 'community-block-title'} - assert_tag :div, :attributes => {:class => 'community-block-description'} - end - - 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 :span, :attributes => {:class => 'community-block-button icon-remove'} - end - - 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_match /\{"Send an e-mail":\{"href":"\/contact\/#{@community.identifier}\/new"\}\}/, @response.body - end - - should 'display *report* button when the user is logged in and is a member of the community' do - get :index, :profile => @community.identifier - assert_match /\{"Report abuse":\{"href":"\/profile\/#{@community.identifier}\/report_abuse"\}\}/, @response.body - end - - 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 :span, :attributes => {:class => 'community-block-button icon-add'} - end - - should 'display *control panel* link option when the user is logged in and is community admin' do - get :index, :profile => @community.identifier - assert_match /\{"Control panel":\{"href":"\/myprofile\/#{@community.identifier}"\}\}/, @response.body - end - - should 'display *join* button when the user is not logged in' do - logout - get :index, :profile => @community.identifier - assert_tag :span, :attributes => {:class => 'community-block-button icon-add'} - end - - should 'not display *arrow* button when the user is not logged in' do - logout - get :index, :profile => @community.identifier - assert_no_tag :span, :attributes => {:class => 'community-block-button icon-arrow'} - end - -end diff --git a/plugins/community_block/views/community_block.html.erb b/plugins/community_block/views/community_block.html.erb index b2d319b..7a1f9c2 100644 --- a/plugins/community_block/views/community_block.html.erb +++ b/plugins/community_block/views/community_block.html.erb @@ -23,7 +23,7 @@ <%= link_to( content_tag('span','',:class => 'community-block-button icon-arrow'), '#', - :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false;", + :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false;", :class => 'simplemenu-trigger') %> <% end %> @@ -32,11 +32,11 @@ <% if profile.members.include?(user) || profile.already_request_membership?(user) %> <%= link_to( content_tag('span', '', :class => 'community-block-button icon-remove'), - profile.leave_url) %> + profile.leave_url, :class => 'join-community') %> <% else %> <%= link_to( content_tag('span', '', :class => 'community-block-button icon-add'), - profile.join_url) %> + profile.join_url, :class => 'join-community') %> <% end %> <% else %> <%= link_to( -- libgit2 0.21.2