From cf9140ee2264b6cc90caf69b60a4404ff4cda7a2 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 30 Dec 2009 00:38:51 -0300 Subject: [PATCH] Redirecting logged users if tries to signup/login --- app/controllers/public/account_controller.rb | 7 +++++++ features/login.feature | 5 +++++ features/publish_article.feature | 1 + features/signup.feature | 7 +++++++ features/support/paths.rb | 3 +++ test/functional/account_controller_test.rb | 2 ++ test/integration/enterprise_registration_test.rb | 4 +++- 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 04667d7..f935d78 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -5,6 +5,7 @@ class AccountController < ApplicationController require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] + before_filter :redirect_if_logged_in, :only => [:login, :signup] # say something nice, you goof! something sweet. def index @@ -291,4 +292,10 @@ class AccountController < ApplicationController end end + def redirect_if_logged_in + if logged_in? + go_to_initial_page + end + end + end diff --git a/features/login.feature b/features/login.feature index 8c9db1e..7b61281 100644 --- a/features/login.feature +++ b/features/login.feature @@ -39,3 +39,8 @@ Feature: login | Password | 123456 | When I press "Log in" Then I should be on Joao Silva's control panel + + Scenario: be redirected if user goes to login page and is logged + Given I am logged in as "joaosilva" + And I go to login page + Then I should be on Joao Silva's control panel diff --git a/features/publish_article.feature b/features/publish_article.feature index 3530c37..af4e005 100644 --- a/features/publish_article.feature +++ b/features/publish_article.feature @@ -40,6 +40,7 @@ Feature: publish article And I follow "Spread" And I check "Sample Community" And I press "Publish" + And I am not logged in And I am logged in as "mariasilva" And "Maria Silva" is a member of "Sample Community" And I am on Maria Silva's control panel diff --git a/features/signup.feature b/features/signup.feature index 141c3f5..bf28017 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -15,3 +15,10 @@ Feature: signup And I press "Sign up" Then I should see "Thanks for signing up!" + Scenario: be redirected if user goes to signup page and is logged + Given the following users + | login | name | + | joaosilva | Joao Silva | + Given I am logged in as "joaosilva" + And I go to signup page + Then I should be on Joao Silva's control panel diff --git a/features/support/paths.rb b/features/support/paths.rb index 70c07cd..ddc22dd 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -29,6 +29,9 @@ module NavigationHelpers when /^login page$/ '/account/login' + when /^signup page$/ + '/account/signup' + when /^(.*)'s control panel$/ '/myprofile/%s' % Profile.find_by_name($1).identifier diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index ace9ee9..81a87fc 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase should 'redirect to where user was on login' do @request.env["HTTP_REFERER"] = '/bli' u = new_user + @controller.stubs(:logged_in?).returns(false) post :login, :user => {:login => 'quire', :password => 'quire'} assert_redirected_to '/bli' @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase assert_difference User, :count do new_user(:login => 'user1', :email => 'user@example.com') assert assigns(:user).valid? + @controller.stubs(:logged_in?).returns(false) new_user(:login => 'user2', :email => 'user@example.com') assert assigns(:user).errors.on(:email) end diff --git a/test/integration/enterprise_registration_test.rb b/test/integration/enterprise_registration_test.rb index cc95802..73e3442 100644 --- a/test/integration/enterprise_registration_test.rb +++ b/test/integration/enterprise_registration_test.rb @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest code = CreateEnterprise.find(:first, :order => 'id desc').code + post '/account/logout' + # steps done by the validator validator = create_user_with_permission('validator', 'validate_enterprise', org) login 'validator', 'validator' - + get "/myprofile/myorg/enterprise_validation" assert_response :success assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } -- libgit2 0.21.2