diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index f3f7c2c..ce51dae 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -18,6 +18,7 @@ class AccountController < ApplicationController if @user and @user.activate @message = _("Your account has been activated, now you can log in!") check_redirection + session[:join] = params[:join] unless params[:join].blank? render :action => 'login', :userlogin => @user.login else session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") @@ -36,7 +37,7 @@ class AccountController < ApplicationController self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] if logged_in? - check_join_in_community(self.current_user) + join_community(self.current_user) if params[:remember_me] == "1" self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } @@ -104,7 +105,7 @@ class AccountController < ApplicationController end if @user.activated? self.current_user = @user - check_join_in_community(@user) + join_community(@user) go_to_signup_initial_page else @register_pending = true @@ -453,4 +454,12 @@ class AccountController < ApplicationController @user.update_attributes(:return_to => nil) end end + + def join_community(user) + profile_to_join = session[:join] + unless profile_to_join.blank? + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) + session.delete(:join) + end + end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index bfa901e..95655d7 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -477,25 +477,6 @@ class ProfileControllerTest < ActionController::TestCase assert_equal "/profile/#{community.identifier}", @request.session[:previous_location] end - should 'redirect to login after user not logged asks to join a community' do - community = Community.create!(:name => 'my test community') - - get :join_not_logged, :profile => community.identifier - - assert_equal community.identifier, @request.session[:join] - assert_redirected_to :controller => :account, :action => :login - end - - should 'redirect to join after user logged asks to join_not_logged a community' do - community = Community.create!(:name => 'my test community') - - login_as(profile.identifier) - get :join_not_logged, :profile => community.identifier - - assert_equal community.identifier, @request.session[:join] - assert_redirected_to :controller => :profile, :action => :join - end - should 'show number of published events in index' do profile.articles << Event.new(:name => 'Published event', :start_date => Date.today) profile.articles << Event.new(:name => 'Unpublished event', :start_date => Date.today, :published => false) @@ -1195,7 +1176,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} article.reload get :index, :profile => profile.identifier - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } end should "view more comments paginated" do @@ -1221,7 +1202,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} profile.reload get :index, :profile => profile.identifier - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } end should "view more replies paginated" do -- libgit2 0.21.2