diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 3eb0774..21f812b 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -8,18 +8,6 @@ class FriendsController < MyProfileController end end - def add - @friend = Person.find(params[:id]) - if request.post? && params[:confirmation] - # FIXME this shouldn't be in Person model? - AddFriend.create!(:person => profile, :friend => @friend, :group_for_person => params[:group]) - - session[:notice] = _('%s still needs to accept being your friend.') % @friend.name - # FIXME shouldn't redirect to the friend's page? - redirect_to :action => 'index' - end - end - def remove @friend = profile.friends.find(params[:id]) if request.post? && params[:confirmation] diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 45b83df..ac3ede9 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -1,9 +1,9 @@ class ProfileController < PublicController needs_profile - before_filter :check_access_to_profile, :except => [:join, :index] - before_filter :store_before_join, :only => [:join] - before_filter :login_required, :only => [:join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities] + before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index] + before_filter :store_before_join, :only => [:join, :join_not_logged] + before_filter :login_required, :only => [:join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities] helper TagsHelper @@ -82,18 +82,26 @@ class ProfileController < PublicController end def join - @wizard = params[:wizard] - if request.post? && params[:confirmation] - profile.add_member(current_user.person) - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? - if @wizard - redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + if !user.memberships.include?(profile) + profile.add_member(user) + if profile.closed? + render :text => _('%s administrator still needs to accept you as member.') % profile.name else - redirect_to_before_join + render :text => _('You just became a member of %s.') % profile.name end else - if current_user.person.memberships.include?(profile) - session[:notice] = _('You are already a member of "%s"') % profile.name + render :text => _('You are already a member of %s.') % profile.name + end + end + + def join_not_logged + if request.post? + profile.add_member(user) + session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? + redirect_to_before_join + else + if user.memberships.include?(profile) + session[:notice] = _('You are already a member of %s') % profile.name redirect_to profile.url return end @@ -104,20 +112,37 @@ class ProfileController < PublicController end def leave - @wizard = params[:wizard] - @back_to = params[:back_to] || request.referer - if request.post? && params[:confirmation] + if user.memberships.include?(profile) profile.remove_member(current_user.person) - if @wizard - redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true - else - back = @back_to || profile.url - redirect_to back - end + render :text => _('You just left %s.') % profile.name else - if request.xhr? - render :layout => false - end + render :text => _('You are already a member of %s.') % profile.name + end + end + + def check_membership + if user.memberships.include?(profile) + render :text => 'true' + else + render :text => 'false' + end + end + + def add + # FIXME this shouldn't be in Person model? + if !user.memberships.include?(profile) + AddFriend.create!(:person => user, :friend => profile) + render :text => _('%s still needs to accept being your friend.') % profile.name + else + render :text => _('You are already a friend of %s.') % profile.name + end + end + + def check_friendship + if user == profile || user.already_request_friendship?(profile) || user.is_a_friend?(profile) + render :text => 'true' + else + render :text => 'false' end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4107334..5585336 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -515,24 +515,27 @@ module ApplicationHelper if environment.enabled?(:show_balloon_with_profile_links_when_clicked) if profile.kind_of?(Person) [ - {_('Home Page') => url_for(profile.url)}, - {_('Wall') => url_for(profile.public_profile_url)}, - {_('Friends') => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}, - {_('Communities') => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)} + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, + {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}}, + {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}}, + {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend'}} ] elsif profile.kind_of?(Community) [ - {_('Home Page') => url_for(profile.url)}, - {_('Wall') => url_for(profile.public_profile_url)}, - {_('Members') => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}, - {_('Agenda') => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)} + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, + {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community'}}, + {_('Leave') => {:href => url_for(profile.leave_url), :class => 'leave-community'}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}} ] elsif profile.kind_of?(Enterprise) [ - {_('Home Page') => url_for(profile.url)}, - {_('Products') => catalog_path(profile.identifier)}, - {_('Members') => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}, - {_('Agenda') => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)} + {_('Products') => {:href => catalog_path(profile.identifier)}}, + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email'}}, ] else [] @@ -543,17 +546,24 @@ module ApplicationHelper # displays a link to the profile homepage with its image (as generated by # #profile_image) and its name below it. def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) - if profile.class == Person - name = profile.short_name + name = profile.short_name + if profile.person? city = content_tag 'span', content_tag( 'span', profile.city, :class => 'locality' ), :class => 'adr' + url = url_for(profile.check_friendship_url) + trigger_class = 'person-trigger' else - name = profile.short_name city = '' + url = url_for(profile.check_membership_url) + if profile.community? + trigger_class = 'community-trigger' + elsif profile.enterprise? + trigger_class = 'enterprise-trigger' + end end extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) links = links_for_balloon(profile) content_tag tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger' ) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + @@ -571,8 +581,9 @@ module ApplicationHelper def community_image_link( profile, size=:portrait, tag='li' ) name = h(profile.name) links = links_for_balloon(profile) + url = url_for(profile.check_membership_url) content_tag tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger' ) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => 'menu-submenu-trigger community-trigger', :url => url) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + content_tag( 'span', name, :class => 'org' ) + diff --git a/app/models/profile.rb b/app/models/profile.rb index 5fdb43a..72c74bb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -426,6 +426,22 @@ class Profile < ActiveRecord::Base { :profile => identifier, :controller => 'profile', :action => 'join' } end + def join_not_logged_url + { :profile => identifier, :controller => 'profile', :action => 'join_not_logged' } + end + + def check_membership_url + { :profile => identifier, :controller => 'profile', :action => 'check_membership' } + end + + def add_url + { :profile => identifier, :controller => 'profile', :action => 'add' } + end + + def check_friendship_url + { :profile => identifier, :controller => 'profile', :action => 'check_friendship' } + end + def public_profile_url generate_url(:profile => identifier, :controller => 'profile', :action => 'index') end diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml index 2629f8d..ce2a063 100644 --- a/app/views/blocks/profile_info_actions/community.rhtml +++ b/app/views/blocks/profile_info_actions/community.rhtml @@ -3,12 +3,14 @@ <% if profile.members.include?(user) %>
  • - <%= lightbox_link_to content_tag('span', _('Leave')), profile.leave_url, :class => 'button with-text icon-delete', :title => _('Leave this community') %> + <%= button(:delete, content_tag('span', __('Leave')), profile.leave_url, :class => 'leave-community', :title => _("Leave 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) %>
  • - <%= lightbox_link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %> + <%= button(:delete, content_tag('span', __('Leave')), 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', :title => _("Join community"), :style => 'position: relative;') %>
  • <% end %> <% end %> @@ -22,7 +24,7 @@ <% else %>
  • - <%= link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %> + <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, :class => 'button with-text icon-add', :title => _('Join this community') %>
  • <% end %> diff --git a/app/views/blocks/profile_info_actions/person.rhtml b/app/views/blocks/profile_info_actions/person.rhtml index fb93798..b078209 100644 --- a/app/views/blocks/profile_info_actions/person.rhtml +++ b/app/views/blocks/profile_info_actions/person.rhtml @@ -2,7 +2,9 @@ <%if logged_in? && (user != profile) %> <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> -
  • <%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %>
  • +
  • + <%= button(:add, content_tag('span', __('Add friend')), profile.add_url, :class => 'add-friend', :title => _("Add friend"), :style => 'position: relative;') %> +
  • <% end %> <% if user.is_a_friend?(profile) && profile.enable_contact? %> diff --git a/app/views/friends/add.rhtml b/app/views/friends/add.rhtml deleted file mode 100644 index f56f64e..0000000 --- a/app/views/friends/add.rhtml +++ /dev/null @@ -1,26 +0,0 @@ -

    <%= __('Adding %s as a friend') % @friend.name %>

    - -

    -<%= __('Are you sure you want to add %s as your friend?') % @friend.name %> -

    - -

    - -<%= __('Note that %s will need to accept being added as your friend.') % @friend.name %> - -

    - -<% form_tag do %> - <%= hidden_field_tag(:confirmation, 1) %> - -
    - <%= __('Classify your new friend %s: ') % @friend.name %> - <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups, :maxlength => 150) %> -

    - <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> -

    -
    - - <%= submit_button(:ok, __("Yes, I want to add %s as my friend") % @friend.name) %> - <%= button(:cancel, _("No, I don't want"), :action => 'index') %> -<% end %> diff --git a/app/views/layouts/_javascript.rhtml b/app/views/layouts/_javascript.rhtml index 9039f0e..086a9c8 100644 --- a/app/views/layouts/_javascript.rhtml +++ b/app/views/layouts/_javascript.rhtml @@ -1 +1 @@ -<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', :cache => 'cache-general' %> +<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery.cookie', 'reflection', 'add-and-join', :cache => 'cache-general' %> diff --git a/app/views/profile/_private_profile.rhtml b/app/views/profile/_private_profile.rhtml index 1bff167..1d5cae3 100644 --- a/app/views/profile/_private_profile.rhtml +++ b/app/views/profile/_private_profile.rhtml @@ -7,10 +7,10 @@ <% button_bar do %> <% if @action == :join && logged_in? %> - <%= lightbox_link_to content_tag('span', _('Join')), profile.join_url, :class => 'button with-text icon-add', :title => _('Join this community') %> + <%= button(:add, content_tag('span', __('Join')), profile.join_url, :class => 'join-community', :title => _("Join community"), :style => 'position: relative;') %> <% end %> <% if @action == :add_friend && logged_in? && !user.already_request_friendship?(profile) %> - <%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %> + <%= button(:add, content_tag('span', __('Add friend')), profile.add_url, :class => 'add-friend', :title => _("Add friend"), :style => 'position: relative;') %> <% end %> <%= button :back, _('Go back'), :back %> <%= button :home, _("Go to %s home page") % environment.name, :controller => 'home' %> diff --git a/features/balloon.feature b/features/balloon.feature index 6f8dcf9..2a0aea7 100644 --- a/features/balloon.feature +++ b/features/balloon.feature @@ -38,7 +38,6 @@ Feature: balloon When I click ".menu-submenu-trigger" Then I should see "Profile" And I should see "Friends" - And I should see "Home Page" @selenium Scenario: I should see balloon when clicked on community block trigger @@ -71,4 +70,3 @@ Feature: balloon When I click ".menu-submenu-trigger" Then I should see "Members" And I should see "Agenda" - And I should see "Home Page" diff --git a/features/join_community.feature b/features/join_community.feature deleted file mode 100644 index 78d44aa..0000000 --- a/features/join_community.feature +++ /dev/null @@ -1,24 +0,0 @@ -Feature: join a community - As a user - I want to join a community - In order to interact with other people - - Background: - Given the following users - | login | name | - | joaosilva | Joao Silva | - Given the following communities - | identifier | name | - | sample-community | Sample Community | - - Scenario: ask confirmation before join community - Given I am logged in as "joaosilva" - And I am on Sample Community's homepage - When I follow "Join" - Then I should see "Are you sure you want to join Sample Community" - - Scenario: dont ask confirmation before join community if already member - Given joaosilva is member of sample-community - And I am logged in as "joaosilva" - When I go to /profile/sample-community - Then I should not see "Are you sure you want to join Community to join" diff --git a/features/my_network_block.feature b/features/my_network_block.feature index b5ef0fb..09c8e81 100644 --- a/features/my_network_block.feature +++ b/features/my_network_block.feature @@ -23,7 +23,6 @@ Feature: my_network_block Then I should see "2 communities" When I go to Public Community's homepage And I follow "Join" - And I press "Yes, I want to join." When I go to Joao Silva's homepage Then I should see "3 communities" @@ -37,7 +36,6 @@ Feature: my_network_block Then I should see "One community" When I go to Public Community's homepage And I follow "Join" - And I press "Yes, I want to join." When I go to Joao Silva's homepage Then I should see "2 communities" diff --git a/features/private_profile.feature b/features/private_profile.feature index bc6983b..cea107f 100644 --- a/features/private_profile.feature +++ b/features/private_profile.feature @@ -17,7 +17,6 @@ Feature: private profiles When I go to Safernet's homepage Then I should see "members only" When I follow "Join" - And I press "Yes, I want to join" And "joao" is accepted on community "Safernet" Then "joao" should be a member of "Safernet" When I go to Safernet's homepage @@ -27,5 +26,4 @@ Feature: private profiles Given I am logged in as "joao" When I go to shygirl's homepage Then I should see "friends only" - When I follow "Add friend" - And I press "Yes, I want" + And I follow "Add friend" diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js new file mode 100644 index 0000000..ddc4ee5 --- /dev/null +++ b/public/javascripts/add-and-join.js @@ -0,0 +1,94 @@ +jQuery(function($) { + + $(".add-friend").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(); + display_notice(data); + }); + return false; + }) + + $(".join-community").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(function(){ + clicked.css("display","none"); + clicked.parent().parent().find(".leave-community").fadeIn(); + clicked.parent().parent().find(".leave-community").css("display", ""); + }); + clicked.css("cursor",""); + $(".small-loading").remove(); + display_notice(data); + }); + return false; + }) + + $(".leave-community").live('click', function(){ + clicked = $(this) + url = clicked.attr("href"); + loading_for_button(this); + $.post(url, function(data){ + clicked.fadeOut(function(){ + clicked.css("display","none"); + clicked.parent().parent().find(".join-community").fadeIn(); + clicked.parent().parent().find(".join-community").css("display", ""); + }); + clicked.css("cursor",""); + $(".small-loading").remove(); + display_notice(data); + }); + return false; + }) + + $(".person-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true"){ + clicked.parent().find(".add-friend").fadeOut(function(){ + clicked.parent().find(".send-an-email").fadeIn(); + }) + } + else if(data == "false"){ + clicked.parent().find(".send-an-email").fadeOut(function(){ + clicked.parent().find(".add-friend").fadeIn(); + }); + } + }) + }) + + $(".community-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true"){ + clicked.parent().find(".join-community").fadeOut(function(){ + clicked.parent().find(".leave-community").fadeIn(); + clicked.parent().find(".send-an-email").fadeIn(); + }); + } + else if(data == "false"){ + clicked.parent().find(".send-an-email").fadeOut(); + clicked.parent().find(".leave-community").fadeOut(function(){ + clicked.parent().find(".join-community").fadeIn(); + }); + } + }) + }) + + $(".enterprise-trigger").click(function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + if(data == "true") + clicked.parent().find(".send-an-email").fadeIn(); + else if(data == "false") + clicked.parent().find(".send-an-email").fadeOut(); + }) + }) +}); diff --git a/public/javascripts/application.js b/public/javascripts/application.js index fdd6cda..c614f08 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -263,7 +263,11 @@ function toggleSubmenu(trigger, title, link_list) { content.append('

    ' + title + '

    '); jQuery.each(link_list, function(index, link_hash) { for (label in link_hash) { - list.append('
  • ' + label + '
  • '); + options = ""; + jQuery.each(link_hash[label], function(option, value){ + options += option +'="'+ value + '" '; + }) + list.append('
  • ' + label + '
  • '); } }); content.append(list); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 43786d2..2443f8b 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2036,7 +2036,7 @@ div#activation_enterprise div { .profile-info-options { padding-top: 20px; text-align: right; - padding-right: 5px; + padding-right: 20px; } .profile-info-block { diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb index c940893..8195417 100644 --- a/test/functional/friends_controller_test.rb +++ b/test/functional/friends_controller_test.rb @@ -34,23 +34,6 @@ class FriendsControllerTest < Test::Unit::TestCase assert_kind_of Array, assigns(:friends) end - should 'confirm addition of new friend' do - get :add, :id => friend.id - - assert_response :success - assert_template 'add' - - ok("must load the friend being added to display") { friend == assigns(:friend) } - - end - - should 'actually add friend' do - assert_difference AddFriend, :count do - post :add, :id => friend.id, :confirmation => '1' - assert_response :redirect - end - end - should 'confirm removal of friend' do profile.add_friend(friend) diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index fafd80b..4695ed7 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -76,49 +76,22 @@ class ProfileControllerTest < Test::Unit::TestCase assert_kind_of Array, assigns(:favorite_enterprises) end - should 'render join template without layout when called with AJAX' do + should 'not render any template when joining community due to Ajax request' do community = Community.create!(:name => 'my test community') login_as(@profile.identifier) - @request.expects(:xhr?).returns(true).at_least_once get :join, :profile => community.identifier assert_response :success - assert_template 'join' + assert_template nil assert_no_tag :tag => 'html' end - should 'render join template with layout in general' do - community = Community.create!(:name => 'my test community') - login_as(@profile.identifier) - @request.expects(:xhr?).returns(false).at_least_once - - get :join, :profile => community.identifier - assert_response :success - assert_template 'join' - assert_tag :tag => 'html' - 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', :attributes => { :href => "/profile/#{community.identifier}/join" } - end - - should 'not show Join This Community button for member users' do + should 'actually add friend' 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', :attributes => { :href => "/myprofile/#{@profile.identifier}/memberships/join/#{community.id}" } - - 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', :attributes => { :href => "/myprofile/#{@profile.identifier}/memberships/leave/#{community.id}" } - + person = fast_create(Person) + assert_difference AddFriend, :count do + post :add, :profile => person.identifier + end end should 'not show enterprises link to enterprise' do @@ -199,26 +172,10 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :child => { :tag => 'span', :content => 'Create a new community' } end - should 'not show Leave 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_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}/memberships/leave/#{community.id}" } - end - - should 'show Leave 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_tag :tag => 'a', - :attributes => { :href => "/profile/#{community.identifier}/leave" } - end - should 'not show Leave 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', :attributes => { :href => "/myprofile/#{@profile.identifier}/memberships/leave/#{community.id}" } + assert_no_tag :tag => 'a', :attributes => { :href => "/profile/#{@profile.identifier}/leave" } end should 'check access before displaying profile' do @@ -414,34 +371,13 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{community.identifier}/new" } end - should 'present confirmation before joining a profile' do - community = Community.create!(:name => 'my test community') - login_as @profile.identifier - get :join, :profile => community.identifier - - assert_response :success - assert_template 'join' - end - should 'actually join profile' do community = Community.create!(:name => 'my test community') login_as @profile.identifier - post :join, :profile => community.identifier, :confirmation => '1' - - assert_response :redirect - assert_redirected_to community.url - - profile = Profile.find(@profile.id) - assert profile.memberships.include?(community), 'profile should be actually added to the community' - end + post :join, :profile => community.identifier - should 'join profile from wizard' do - community = Community.create!(:name => 'my test community') - login_as @profile.identifier - post :join, :profile => community.identifier, :confirmation => '1', :wizard => true - - assert_response :redirect - assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + assert_response :success + assert_template nil profile = Profile.find(@profile.id) assert profile.memberships.include?(community), 'profile should be actually added to the community' @@ -451,7 +387,7 @@ class ProfileControllerTest < Test::Unit::TestCase community = Community.create!(:name => 'my test community', :closed => true) login_as @profile.identifier assert_difference AddMember, :count do - post :join, :profile => community.identifier, :confirmation => '1' + post :join, :profile => community.identifier end end @@ -462,74 +398,18 @@ class ProfileControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'account', :action => 'login' end - should 'present confirmation before leaving a profile' do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - login_as(profile.identifier) - get :leave, :profile => community.identifier - - assert_template 'leave' - assert_tag :tag => 'input', :attributes => {:value => 'Yes, I want to leave.', :type => 'submit'} - end - should 'actually leave profile' do community = Community.create!(:name => 'my test community') community.add_member(profile) assert_includes profile.memberships, community login_as(profile.identifier) - post :leave, :profile => community.identifier, :confirmation => '1' - - profile = Profile.find(@profile.id) - assert_not_includes profile.memberships, community - end - - should 'leave profile when on wizard' do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - login_as(profile.identifier) - post :leave, :profile => community.identifier, :confirmation => '1', :wizard => true - - assert_response :redirect - assert_redirected_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true + post :leave, :profile => community.identifier profile = Profile.find(@profile.id) assert_not_includes profile.memberships, community end - should "offer button to close 'leave community' lightbox" do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - login_as(profile.identifier) - get :index, :profile => community.identifier - - assert_tag :tag => 'a', :content => 'Leave', :attributes => { :href => "/profile/#{community.identifier}/leave", :class => /^lbOn/ } - end - - should 'offer button to cancel leaving community' do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - login_as(profile.identifier) - get :leave, :profile => community.identifier - - assert_tag :tag => 'a', :content => "No, I don't want." - end - - should 'render without layout when use lightbox to leave community' do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - @request.stubs(:xhr?).returns(true) - login_as(profile.identifier) - get :leave, :profile => community.identifier - - assert_no_tag :tag => 'body' # e.g. no layout - end - should 'require login to leave community' do community = Community.create!(:name => 'my test community') get :leave, :profile => community.identifier @@ -537,51 +417,6 @@ class ProfileControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'account', :action => 'login' end - should 'redirect to stored location after leave community' do - community = Community.create!(:name => 'my test community') - community.add_member(profile) - - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go").at_least_once - login_as(profile.identifier) - - post :leave, :profile => community.identifier, :confirmation => '1', :back_to => @request.referer - - assert_redirected_to "/profile/#{community.identifier}/to_go" - end - - should 'store referer location when request leave via get' do - community = Community.create!(:name => 'my test community') - login_as(profile.identifier) - - @request.expects(:referer).returns("/profile/redirect_to").at_least_once - - get :leave, :profile => community.identifier - - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => @request.referer } - end - - should 'store referer location when request join via get' do - community = Community.create!(:name => 'my test community') - login_as(profile.identifier) - - @request.session[:before_join] = "/profile/redirect_to" - - get :join, :profile => community.identifier - - assert_equal '/profile/redirect_to', @request.session[:before_join] - end - - should 'redirect to stored location after join community' do - community = Community.create!(:name => 'my test community') - - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") - login_as(profile.identifier) - - post :join, :profile => community.identifier, :confirmation => '1' - - assert_redirected_to "/profile/#{community.identifier}/to_go" - end - should 'store location before login when request join via get not logged' do community = Community.create!(:name => 'my test community') @@ -598,7 +433,7 @@ class ProfileControllerTest < Test::Unit::TestCase @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") login_as(profile.identifier) - post :join, :profile => community.identifier, :confirmation => '1' + post :join_not_logged, :profile => community.identifier assert_redirected_to "/profile/#{community.identifier}/to_go" diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index e974459..94e1af6 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -484,7 +484,7 @@ class ApplicationHelperTest < Test::Unit::TestCase person.stubs(:url).returns('url for person') person.stubs(:public_profile_url).returns('url for person') links = links_for_balloon(person) - assert_equal ['Home Page', 'Wall', 'Friends', 'Communities'], links.map{|i| i.keys.first} + assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first} end should 'return ordered list of links to balloon to Community' do @@ -495,7 +495,7 @@ class ApplicationHelperTest < Test::Unit::TestCase community.stubs(:url).returns('url for community') community.stubs(:public_profile_url).returns('url for community') links = links_for_balloon(community) - assert_equal ['Home Page', 'Wall', 'Members', 'Agenda'], links.map{|i| i.keys.first} + assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave', 'Send an e-mail'], links.map{|i| i.keys.first} end should 'return ordered list of links to balloon to Enterprise' do @@ -507,7 +507,7 @@ class ApplicationHelperTest < Test::Unit::TestCase enterprise.stubs(:public_profile_url).returns('url for enterprise') stubs(:catalog_path) links = links_for_balloon(enterprise) - assert_equal ['Home Page', 'Products', 'Members', 'Agenda'], links.map{|i| i.keys.first} + assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first} end should 'use favicon from environment theme if does not have profile' do -- libgit2 0.21.2