From 78f01eb33a76bd3670c807ef1adb8de5cb7281af Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 17 Sep 2009 18:40:11 -0300 Subject: [PATCH] ActionItem1247: enhancements on join popup --- app/controllers/public/profile_controller.rb | 17 ++++++++++++++++- app/helpers/application_helper.rb | 1 + test/functional/profile_controller_test.rb | 23 +++++++++++++++++++++++ test/unit/application_helper_test.rb | 30 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 036b638..0f826ce 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -2,6 +2,7 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile + before_filter :store_before_join, :only => [:join] before_filter :login_required, :only => [:join, :refuse_join, :leave] helper TagsHelper @@ -55,7 +56,7 @@ class ProfileController < PublicController if @wizard redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true else - redirect_back_or_default profile.url + redirect_to_before_join end else store_location(request.referer) @@ -104,6 +105,20 @@ class ProfileController < PublicController end end + def store_before_join + session[:before_join] = request.referer unless logged_in? + end + + def redirect_to_before_join + back = session[:before_join] + if back + session[:before_join] = nil + redirect_to back + else + redirect_back_or_default profile.url + end + end + def per_page Noosfero::Constants::PROFILE_PER_PAGE end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d363be8..dcb88bf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -852,6 +852,7 @@ module ApplicationHelper def ask_to_join? return if !environment.enabled?(:join_community_popup) + return if params[:action] == 'join' return unless profile && profile.kind_of?(Community) if (session[:no_asking] && session[:no_asking].include?(profile.id)) return false diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index b593905..a7873c4 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -634,4 +634,27 @@ class ProfileControllerTest < Test::Unit::TestCase 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') + + @request.expects(:referer).returns("/profile/#{community.identifier}") + + get :join, :profile => community.identifier + + assert_equal "/profile/#{community.identifier}", @request.session[:before_join] + end + + should 'redirect to location before login after join community' do + community = Community.create!(:name => 'my test community') + + @request.session[:before_join] = "/profile/#{community.identifier}/to_go" + login_as(profile.identifier) + + post :join, :profile => community.identifier, :confirmation => '1' + + assert_redirected_to "/profile/#{community.identifier}/to_go" + + assert_nil @request.session[:before_join] + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 0a7aba2..f16dbe3 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -350,6 +350,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join unless profile defined' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -359,6 +361,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join unless profile is community' do + stubs(:params).returns({}) e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -368,7 +371,22 @@ class ApplicationHelperTest < Test::Unit::TestCase assert ! ask_to_join? end + should 'not ask_to_join if action join' do + expects(:params).returns({:action => 'join'}) + + e = Environment.default + e.stubs(:enabled?).with(:join_community_popup).returns(true) + stubs(:environment).returns(e) + + c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + stubs(:profile).returns(c) + stubs(:logged_in?).returns(false) + assert ! ask_to_join? + end + should 'ask_to_join if its not logged and in a community' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -380,6 +398,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'ask_to_join if user say so' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -395,6 +415,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join if user say no' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -409,6 +431,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join if environment say no even if its not logged and in a community' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(false) stubs(:environment).returns(e) @@ -419,6 +443,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join if environment say no even if user say so' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(false) stubs(:environment).returns(e) @@ -433,6 +459,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join if its recorded in the session' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) @@ -446,6 +474,8 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not ask_to_join if its recorded in the session even for authenticated users' do + stubs(:params).returns({}) + e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) -- libgit2 0.21.2